In this python dictionary program, we will create a dictionary from two lists. Elements from the first list as keys and elements from the second as its values.
Steps to solve the program
- Take two lists as inputs and create an empty dictionary.
- Combined both lists by using the zip() function.
- Use for loop to iterate over the combined list.
- During iteration add elements from the first list as keys and elements from the second list as its values.
- Print the output.
list1 = ['a','b','c','d','e']
list2 = [12,23,24,25,15,16]
dict1 = {}
for a,b in zip(list1,list2):
dict1[a] = b
print(dict1)
Output :
{'a': 12, 'b': 23, 'c': 24, 'd': 25, 'e': 15}