Convert Two Lists Into a Dictionary in Python Using map() Function

(Last Updated On: 23/03/2023)

Python Program to Convert / Combine Two Lists Into a Dictionary Using map() Function

# Convert or Combine Two Lists Into a Dictionary in python Using map()

# Python3 code to demonstrate
# conversion of lists to dictionary
# using dict() + map()

# initializing lists
keys = ["Chandan", "Pratik", "Praful"]
values = [3, 5, 7]

# Printing original keys-value lists
print ("Original key list is : " + str(keys))
print ("Original value list is : " + str(values))

# using map and dict type casting
# to convert lists to dictionary
res = dict(map(lambda i,j : (i,j) , keys,values))

# Printing resultant dictionary
print ("Resultant dictionary is : " + str(res))

Output:

Original key list is : ['Chandan', 'Pratik', 'Praful']
Original value list is : [3, 5, 7]
Resultant dictionary is : {'Chandan': 3, 'Pratik': 5, 'Praful': 7}

Leave a Reply

Your email address will not be published. Required fields are marked *