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

(Last Updated On: 20/03/2023)

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

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

# Python3 code to demonstrate
# conversion of lists to dictionary
# using zip()

# initializing lists
test_keys = ["Chandan", "Pratik", "Praful"]
test_values = [3, 5, 7]

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

# using zip()
# to convert lists to dictionary
res = dict(zip(test_keys, test_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 *