QuestenaPractice that shows what to review next
Question 37

Why can a list not be used as a key in a Python dictionary?

  1. Lists are unhashable, while dictionary keys must be hashable.Correct answer
  2. Lists are too large to fit in a dictionary entry.
  3. Only strings may be dictionary keys.
  4. A list would create several duplicate keys automatically.

Explanation

Dictionary keys must be hashable, while a list can change its contents and is unhashable. Allowing arbitrary mutable keys would undermine stable lookup, and a dictionary cannot hold simultaneous duplicate equal keys.

Continue with this test

Start practice
Question 37: Why can a list not be used as a key in a Python dictionary? · Python Fundamentals · Questena