Create a dictionary of keys a, b, and c


The program uses the dict and list functions, and the pprint module from the pprint library, to create and display a dictionary num.

The dict function creates the dictionary num by passing key-value pairs as arguments. The keys are strings ("A", "Y", and "Z") and the values are lists of integers, created using the list function and the range function. The range function generates a sequence of integers from the starting number to the ending number (not including the ending number).

The pprint function from the pprint library is used to pretty-print the dictionary num to the console. This makes the output easier to read by adding appropriate whitespace and line breaks.

Finally, a for loop is used to iterate over the key-value pairs in the dictionary num. The items method is used to get the key-value pairs as a sequence of tuples. For each iteration, the key k and value v are printed using the print function. The output of the program will show the key-value pairs in the dictionary num, with each key on one line and its corresponding value on the next line.

Source Code

from pprint import pprint
num = dict(A=list(range(1, 11)), Y=list(range(11, 21)), Z=list(range(21, 31)))
pprint(num)
 
for k,v in num.items():
   print(k, " = ", v)

Output

{'A': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
 'Y': [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
 'Z': [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]}
A  =  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Y  =  [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Z  =  [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]