Why can a tuple of numbers be used as a dictionary key, but a list cannot?
Correct answer A. Dictionary keys must be hashable, and lists are mutable and unhashable
Explanation
A dict locates keys through their hash value, which must never change while the key is stored. Mutable objects like lists are therefore unhashable, and using one as a key raises TypeError. A tuple is hashable when all its items are hashable, so (1, 2) works as a key.
Answer checked How we write and check questions
Discussion