Question:medium

Consider the following dictionaries, D and D1:
D = { "Suman": 40, "Raj": 55, "Raman": 60 }
D1 = { "Aditi": 30, "Amit": 90, "Raj": 20 }

(Answer using built-in Python functions only)

(i)
(a) Write a statement to display/return the value corresponding to the key "Raj" in the dictionary D.

OR

(b) Write a statement to display the length of the dictionary D1.

(ii)
(a) Write a statement to append all the key-value pairs of the dictionary D to the dictionary D1.

OR

(b) Write a statement to delete the item with the given key "Amit" from the dictionary D1.

Show Hint

Use update() to merge dictionaries,
pop() to remove an item, len() to find size,
and square brackets [] to access values by key.
Updated On: Jan 14, 2026
Show Solution

Solution and Explanation

(i) (a) Retrieve the value associated with the key "Raj":
print(D["Raj"])
This command accesses and prints the value for the key "Raj".
OR
(i) (b) Determine the number of elements in D1:
print(len(D1))
This command uses the built-in len() function to count and display the key-value pairs in D1.
(ii) (a) Combine D into D1:
D1.update(D)
The update() method integrates all key-value pairs from D into D1. Existing keys in D1 will have their values overwritten by those from D.
OR
(ii) (b) Remove "Amit" from D1:
D1.pop("Amit")
The pop() method eliminates the entry with the key "Amit" from the dictionary D1.
Was this answer helpful?
0