0

Dictionary

is there is a better way to assign all elements in a list to dictionary values respectively, i have code(here l2 is the list ) i = 0 for key in dict1: dict1[key] = l2[i] i+=1

29th May 2017, 2:18 AM
Vibhu Vashishtha
Vibhu Vashishtha - avatar
1 Answer
+ 2
If you want create a new dictionary, I recommend you the code below def list2dic(key, val): return dict(zip(key, val)) valuelist = [10, 20, 30] keylist = ['key1', 'key2', 'key3'] print(list2dic(keylist, valuelist))
29th May 2017, 4:23 AM
Suyasa
Suyasa - avatar