13
Question Question 10
Create a dictionary 'ODD' of odd numbers between 1 and 10, where the key is the decimal number and the value is the corresponding number in words.
Perform the following operations on this dictionary :
- Display the keys
- Display the values
- Display the items
- Find the length of the dictionary
- Check if 7 is present or not
- Check if 2 is present or not
- Retrieve the value corresponding to the key 9
- Delete the item from the dictionary corresponding to the key 9
>>> ODD = { 1 : 'One', 3 : 'Three', 5 : 'Five', 7 : 'Seven', 9 : 'Nine' }
>>> ODD.keys()
# (1) Display the keys
>>> ODD.values()
# (2) Display the values
>>> ODD.items()
# (3) Display the items
>>> len(ODD)
# (4) Find the length of the dictionary
>>> 7 in ODD
# (5) Check if 7 is present or not
>>> 2 in ODD
# (6) Check if 2 is present or not
>>> ODD[9]
# (7) Retrieve the value corresponding to the key 9
>>> del ODD[9]
# (8) Delete the item from the dictionary corresponding to the key 9Output
dict_keys([1, 3, 5, 7, 9])
dict_values(['One', 'Three', 'Five', 'Seven', 'Nine'])
dict_items([(1, 'One'), (3, 'Three'), (5, 'Five'), (7, 'Seven'), (9, 'Nine')])
5
True
False
Nine