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
- Create three empty lists and an empty dictionary.
- In the first empty list add numbers between 1-5 using a for loop.
- Repeat this process for the second and third lists to add respective numbers.
- Add the three lists with respective keys to the empty dictionary.
- 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]}