Which of the following statements is true about dictionaries in Python ?
Which of the following statements is true about dictionaries in Python ?
Options
Option B — 'A dictionary cannot have two elements with same key' is the true statement, because dictionary keys must always be unique; if a key is repeated during creation, the later value simply overwrites the earlier one.
Marking Scheme
- 11 mark: for correctly selecting option B.
Hint
Dictionary KEYS must be unique; values and key=value combinations have no such restriction.
Quick Oral Answer
A dictionary cannot have two elements with the same key because keys must be unique; if repeated during creation, the last value overwrites the earlier one, but values and even key=value pairs can repeat freely.
Analysis & Explanation
This question checks the fundamental rules that govern Python dictionaries as a mapping (not sequence) data type.
Concept
- A dictionary is a mapping type that stores data as key-value pairs; keys must be unique and hashable (immutable), but values can repeat freely.
Why option B is correct
- If you try to define two entries with the same key, e.g.,
{'a':1, 'a':2}, Python does not raise an error — it silently keeps only the LAST value, proving that duplicate keys cannot coexist as separate elements.
Why other options are wrong
- Option A — a dictionary is a mapping type, not a sequence type (lists, tuples, strings are sequence types with positional/index-based access); dictionaries are accessed by key, not position.
- Option C — values in a dictionary CAN repeat, e.g.,
{'a':1, 'b':1}is perfectly valid, since only keys must be unique. - Option D — a key and its value CAN be identical, e.g.,
{'a':'a'}or{5:5}is valid Python.
Exam trap
- Students often assume dictionaries are sequence types because they can be iterated over, but 'sequence' in Python specifically means ordered, index-accessible types like list/tuple/string.
Common Mistakes
- 1Believing a dictionary is a sequence type because it can be looped over — it is a mapping type, accessed by key not position.
- 2Assuming values in a dictionary must also be unique, like keys.
Interesting Facts
Since Python 3.7, dictionaries officially guarantee insertion order is preserved — but this does not make them a 'sequence' type in the formal sense used for indexing/slicing.
Dictionary keys must be hashable (immutable), which is why lists cannot be used as dictionary keys but tuples can.
Spotted a mistake or something unclear?
Tell us — we fix reported answers fast.
Frequently Asked Questions
What happens if I define a dictionary with a repeated key?
Python does not raise an error; it silently retains only the last key-value pair for that key, discarding the earlier one(s).
Can dictionary values be duplicated?
Yes, dictionary values have no uniqueness restriction — multiple keys can map to the exact same value.