Test Index
CBSE Class 12 Computer Science 2025 Paper Compartment
© examsnet.com
Question : 24 of 37
Marks:
+1,
-0
Assuming that
D1 and D2 are Python dictionaries, write the following statements using built-in functions/methods :(I) (a) To delete all the elements of D1.OR(b) To generate a list of values of D1.(II) (a) To update dictionary D2 with the elements of D1.OR(b) To generate a tuple of keys of D2.
Solution:
(I)(a)
D1.clear() # D1 becomes {}OR (I)(b)list(D1.values()) # e.g. {'a': 1, 'b': 2} -> [1, 2](II)(a)D2.update(D1) # adds D1's pairs to D2; a common key takes D1's valueOR (II)(b)
tuple(D2.keys()) # or tuple(D2) # e.g. {'c': 3, 'a': 1} -> ('c', 'a')© examsnet.com
Go to Question: