Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

How do you access the value of 'x' in the nested dictionary { 'a': { 'b': { 'x': 5 } } }?

View

What will d.get('x', 0) return if 'x' is not in d?

View

How can you merge two dictionaries d1 and d2 in Python 3.9+?

View

What will the following code print?

View

Which method removes a key-value pair from a dictionary?

View

How do you check if a key exists in a dictionary?

View

What does dict.items() return?

View

Can a dictionary have duplicate keys?

View

Which of the following is a valid way to create an empty dictionary?

View

How do you update an existing dictionary with another?

View

How do you access the value of 'x' in the nested dictionary { 'a': { 'b': { 'x': 5 } } }?

dict['a']['b']['x']
dict['a']['x']
dict['x']['b']['a']
dict['a']['b']['y']

What will d.get('x', 0) return if 'x' is not in d?

Raises an error
0
None
{}

How can you merge two dictionaries d1 and d2 in Python 3.9+?

d1 + d2
d1.merge(d2)
d1 | d2
d1.add(d2)

What will the following code print?

d = {'a': 1, 'b': 2} print(d.keys())

['a', 'b']
{'a', 'b'}
dict_keys(['a', 'b'])
['a', 1, 'b', 2]

Which method removes a key-value pair from a dictionary?

pop()
delete()
remove()
discard()

How do you check if a key exists in a dictionary?

key in dict
key.exists(dict)
dict.contains(key)
if key in values(dict)

What does dict.items() return?

A list of keys
A list of values
A view object of key-value pairs
None of the above

Can a dictionary have duplicate keys?

Yes
No

Which of the following is a valid way to create an empty dictionary?

d = {}
d = dict()
Both a and b
d = []

How do you update an existing dictionary with another?

dict1.append(dict2)
dict1.update(dict2)
dict1.add(dict2)
dict1.extend(dict2)