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

What will d = {'a': 1, 'b': 2}; d.pop('a') return?

View

What will {'a': 1, 'b': 2}.get('c', 'default') return?

View

How can you delete all key-value pairs in a dictionary?

View

What will be the result of list({'a': 1, 'b': 2}.keys())?

View

How can you create a dictionary with default values?

View

What does the update() method do in dictionaries?

View

Can dictionary keys be mutable types?

View

What will dict([('a', 1), ('b', 2)]) produce?

View

What will d = {'a': 1}; d.setdefault('b', 2) return?

View

What will d = {'a': 1}; del d['a']; print(d) output?

View

What will d = {'a': 1, 'b': 2}; d.pop('a') return?

{'a': 1}
1
{'b': 2}
Error

What will {'a': 1, 'b': 2}.get('c', 'default') return?

'c'
'default'
None
Error

How can you delete all key-value pairs in a dictionary?

dict.delete()
dict.clear()
del dict
dict.remove()

What will be the result of list({'a': 1, 'b': 2}.keys())?

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

How can you create a dictionary with default values?

dict.fromkeys(['a', 'b'], 0)
dict(['a', 'b'], 0)
defaultdict(['a', 'b'])
dict.keys(['a', 'b'], 0)

What does the update() method do in dictionaries?

Adds new key-value pairs
Replaces existing values if keys match
Does both a and b
Removes duplicate keys

Can dictionary keys be mutable types?

Yes
No

What will dict([('a', 1), ('b', 2)]) produce?

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

What will d = {'a': 1}; d.setdefault('b', 2) return?

{'a': 1, 'b': 2}
2
'b'
Error

What will d = {'a': 1}; del d['a']; print(d) output?

{}
{'a': None}
{'a': 0}
Error