Dictionaries & Sets · Question 14 · Medium

Which of the following values can be used as a dictionary key?

  1. [1, 2]
  2. (1, 2)
  3. {1, 2}
  4. {"a": 1}
Answer and explanation

Answer: B. (1, 2)

Explanation: A key must be hashable. A tuple of immutable values is hashable, while lists, sets and dictionaries are mutable and cannot be hashed.

Previous: A loop over items() adds up only the marks above 70. What total is printed? · Next: pop() is called for a key that exists and for one that does not. What does…

Practise dictionaries & sets

Try a fresh set of dictionaries & sets questions with an explanation after every answer, free and without signing up: Dictionaries & Sets practice. Or sit a full placement mock test.

More dictionaries & sets questions

More python practice

Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge