Programs · Program 10-5
Q.Program 10-5: 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:
(a) Display the keys
(b) Display the values
(c) Display the items
(d) Find the length of the dictionary
(e) Check if 7 is present or not
(f) Check if 2 is present or not
(g) Retrieve the value corresponding to the key 9
(h) Delete the item from the dictionary corresponding to the key 9
Uttar Pradesh UpmspTextbookSubjective· 4mImportance★★★★★est
30% · 9/30 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →One dictionary, eight one-line operations: keys(), values(), items(), len(), membership with in (True for 7, False for 2), lookup ODD[9] -> 'Nine', and del ODD[9] to remove the pair.
The idea. This program is a tour of the core dictionary interface. The decimal numbers are the keys (they identify entries), the words are the values. Every requested operation maps to a built-in method or operator — nothing needs a loop.
Program 10-5:
ODD = {1: 'One', 3: 'Three', 5: 'Five', 7: 'Seven', 9: 'Nine'}
print("Dictionary ODD:", ODD)
print("(a) Keys:", ODD.keys())
print("(b) Values:", ODD.values())
print("(c) Items:", ODD.items())
print("(d) Length:", len(ODD))
print("(e) Is 7 present?:", 7 in ODD)
print("(f) Is 2 present?:", 2 in ODD)
print("(g) Value of key 9:", ODD[9])
del ODD[9] # (h)
print("(h) After deleting key 9:", ODD)
Verified output:
Dictionary ODD: {1: 'One', 3: 'Three', 5: 'Five', 7: 'Seven', 9: 'Nine'}
(a) Keys: dict_keys([1, 3, 5, 7, 9])
(b) Values: dict_values(['One', 'Three', 'Five', 'Seven', 'Nine'])
(c) Items: dict_items([(1, 'One'), (3, 'Three'), (5, 'Five'), (7, 'Seven'), (9, 'Nine')])
(d) Length: 5
(e) Is 7 present?: True
(f) Is 2 present?: False
(g) Value of key 9: Nine
(h) After deleting key 9: {1: 'One', 3: 'Three', 5: 'Five', 7: 'Seven'}
Operation notes:
- (a)-(c)
keys(),values()anditems()return view objects (dict_keys,dict_values,dict_items) — live windows onto the dictionary, printable directly and convertible withlist()when needed. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.