Make a dictionnary with two lists
We've two lists :
l1 = ["name", "age", "sex"]
l2 = ["John" , 23, "man"]
Next, if we want a dictionnary with the keys in the first list and the values in the second we can do :
d = dict(zip(l1, l2))
print d
# >>> {'age': 23, 'name': 'John', 'sex': 'man'}
Very useful for CSV parsing
Written by Kokopak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#