Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

zip Lists to a Dictionary

cast_names = ["Barney", "Robin", "Ted", "Lily", "Marshall"]
cast_heights = [72, 68, 72, 66, 76]

cast = dict(zip(cast_names, cast_heights))
print(cast)

#The order of elements in this output may vary since dictionaries are unordered
>>>{'Lily': 66, 'Barney': 72, 'Marshall': 76, 'Ted': 72, 'Robin': 68}
Source by classroom.udacity.com #
 
PREVIOUS NEXT
Tagged: #zip #Lists #Dictionary
ADD COMMENT
Topic
Name
5+3 =