Q:

create dictionary python from two lists

>>> keys = ['a', 'b', 'c']
>>> values = [1, 2, 3]
>>> dictionary = dict(zip(keys, values))
>>> print(dictionary)
{'a': 1, 'b': 2, 'c': 3}
3
mydict = dict(zip(list1, list2))
0
# Python3 code to demonstrate  
# conversion of lists to dictionary 
# using zip() 
  
# initializing lists 
test_keys = ["Rash", "Kil", "Varsha"] 
test_values = [1, 4, 5] 
  
# Printing original keys-value lists 
print ("Original key list is : " + str(test_keys)) 
print ("Original value list is : " + str(test_values)) 
  
# using zip() 
# to convert lists to dictionary 
res = dict(zip(test_keys, test_values)) 
  
# Printing resultant dictionary  
print ("Resultant dictionary is : " +  str(res)) 
0

New to Communities?

Join the community