Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

zip() in Python: Get elements from multiple lists

d = {'k1': 1, 'k2': 2}

# d.update(k3=3, k3=300)
# SyntaxError: keyword argument repeated: k3

d = {'k1': 1, 'k2': 2}

d.update([('k3', 3), ('k3', 300)])
print(d)
# {'k1': 1, 'k2': 2, 'k3': 300}

d = {'k1': 1, 'k2': 2}

keys = ['k3', 'k3']
values = [3, 300]

d.update(zip(keys, values))
print(d)
# {'k1': 1, 'k2': 2, 'k3': 300}
Source by note.nkmk.me #
 
PREVIOUS NEXT
Tagged: #Get #elements #multiple #lists
ADD COMMENT
Topic
Name
1+2 =