Assignment No: 8
1. Do the following in Python shell.
a) Create a dictionary which has at least 5 items. Print it.
b) Update any one of the item. Print it.
c) Add one more item. Print it.
d) Delete a particular item mentioning key value. Print it.
e) Delete the first item without mentioning key value. Print the dictionary.
f) Remove all items from the dictionary.
g) Delete the dictionary.
h) Create a dictionary with each item being a pair of a number and its square. Do it in single line of code.
i) Do the same as above only for odd numbers.
h) Print all items and keys of the dictionary.
j) Calculate the length of the dictionary.
k) Sort the items in the dictionary.
l) Create two dictionaries. Concatenate them.
m) Pop an element not present from the dictionary, provided a default value.
n) Sort the items in frozen set.
2. Write a program to check whether an item is present or not.
3. Write a program to print all the items of the dictionary using loop.
4. Write a program to map two lists (one containing color names and the other containing color codes) into dictionary.
5. Write a program to get the maximum and minimum value in a dictionary.
6. Write a program to store student data in dictionary (name, class, subjects). Remove duplicate entries.
7. Write a Python program to concatenate following dictionaries to create a new one using loop.
8. Write a Python program to multiply all the items in a dictionary.
9. Write a Python program to sum all the items in a dictionary.
10. Write a Python program to sort a dictionary by key.
11. Write a Python program to check a dictionary is empty or not.
12. Write a Python program that generates a set of prime numbers and another set of odd numbers. Demonstrate the result
of union, intersection, difference, and symmetric difference operations on these sets.
13. Write a Python program that creates two sets. One of even numbers in range 1-10 and the other has all composite
numbers in range 1-20. Demonstrate the use of all( ), issuperset(), len(), and sum() functions on the sets.
14. Write a Python program which creates two dictionaries. One that stores conversion values from meters to centimeters
and the other that stores the reverse.
15. Write a Python program to store a sparse matrix as a dictionary.
16. Write a Python program that creates a dictionary of cubes of odd numbers in the range 1-10 (in a single statement).
17. Write a Python program that inverts a dictionary, i.e., it makes key of one dictionary value of another and vice versa.
18. Write a Python program that has dictionary of names of students and a list of their marks in 4 subjects. Create another
dictionary from this dictionary that has name of the students and their total marks. Find out the topper and his/ her
score.
19. Write a Python program that displays information about an employee. Use nested dictionary to do this task.
20. Create a dictionary of products purchased and their MRPs. Calculate the bill and display to the customer.
21. Write a program that has a dictionary of your friends’ name (as keys) and their birthdays. Print the items in the
dictionary in a sorted order. Prompt the user to enter a name and check if it is present in the dictionary. If the name does
not exist, then ask the user to enter DOB. Add the details in the dictionary.
22. Write a Python program that displays a menu and its price. Take the order from the customer. Check if the ordered
product is in the menu. In case it is not there, the customer should be asked to reorder and if it is present, then product
should be added in the bill.
