Python program to create a dictionary

In this python dictionary program, we will create a dictionary of keys a, b, and c where each key has as value a list from 1-5, 6-10, and 11-15 respectively. 

Steps to solve the program
  1. Create three empty lists and an empty dictionary.
  2. In the first empty list add numbers between 1-5 using a for loop.
  3. Repeat this process for the second and third lists to add respective numbers.
  4. Add the three lists with respective keys to the empty dictionary.
  5. Print the output.
				
					l1= []
for i in range(1,6):
    l1.append(i)
    
l2 = []
for i in range(6,11):
    l2.append(i)
    
l3 = []
for i in range(11,16):
    l3.append(i)
    
dict1 = {}
dict1["a"] = l1
dict1["b"] = l2
dict1["c"] = l3

print(dict1)
				
			

Output :

				
					{'a': [1, 2, 3, 4, 5], 'b': [6, 7, 8, 9, 10], 'c': [11, 12, 13, 14, 15]}
				
			

match key values in two dictionaries.

drop empty Items from a given dictionary.

Leave a Comment