I'm new to Python and I'm currently working by solving questions to improve my coding skills. I have two Lists
with equal sizes and I want to add those values from the lists into a dictionary
as key-value pairs. How can I do that? From my research, I found that I could use the dict
to add the elements from the list to a dictionary as only keys or values.
Example:
List_1 = [1, 2, 3, 4]
List_2 = [11, 12, 13, 14]
My dictionary should contain:
<'1':'11', '2':'12', '3':'13', '4':'14'>
My code: d = dict.fromkeys(List_1, 0)
- but this only adds the elements in List_1
as keys and 0's as values. But if i replace the 0 with List_2
, the output is quite weird and not as expected.
Please help me in understanding this. Thanks in advance. Your help is much appreciated.