Python Program to create a dictionary from two lists.

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
  1. Take two lists as inputs and create an empty dictionary.
  2. Combined both lists by using the zip() function.
  3. Use for loop to iterate over the combined list.
  4. During iteration add elements from the first list as keys and elements from the second list as its values.
  5. 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}
				
			

get a list of odd and even keys from the dictionary

store squares of even and cubes of odd numbers in a dictionary using dictionary comprehension.

Leave a Comment