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
3 odpowiedzi
+ 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))