[Tutor] Functional question

Kent Johnson kent37 at tds.net
Sat Aug 6 16:15:27 CEST 2005

Bernard Lebel wrote:
> Thanks Kent.
> I had tried the very same thing, but with a list instead of a tuple,
> and got an got this:
>>>>dMap[ ['allo','bonjour'] ] = 'salut'
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: list objects are unhashable
> It never crossed my mind that a tuple would do it.

That is one of the key differences between a list and a tuple - a tuple can be used as a dictionary key. Dictionary keys must be hashable, which in practice means they must be immutable. A tuple whose members are also immutable works fine as a key.


More information about the Tutor mailing list