Python @ DjangoSpin

PyPro #40 Merging two Lists into a Dictionary

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Merging two Lists into a Dictionary in Python

Merging two Lists into a Dictionary in Python

Merging two Lists into a Dictionary: Write a Python program to create a dictionary with keys coming from one list and corresponding values coming from another list. Hint: Consider using the constructor of builtin class zip.

Merging two Lists into a Dictionary

keys = [1, 2, 3, 4, 5]
values = ['one', 'two', 'three', 'four', 'five']
dictionaryOfNumbers = dict( zip(keys, values) )
print(dictionaryOfNumbers)                 # {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five'}

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply