Instagram
youtube
Facebook
Twitter

Python Program to Convert Two Lists into a Dictionary

A Python Program to Convert Two Lists into a Dictionary

Code Explanation:

List Definition:
Two separate lists are defined — one for keys (keys) and one for values (values).

Using zip():
The zip() function combines the two lists element-wise into pairs.

Using dict():
dict() converts the zipped pairs into a dictionary.

Print Result:
The final dictionary is printed using print().

 

Program:

keys = ['name', 'age', 'city']

values = ['Alice', 25, 'New York']

result = dict(zip(keys, values))

print("Converted dictionary:", result)