[Python-Dev] dict containment annoyance

David Hopwood david.nospam.hopwood at blueyonder.co.uk
Sat Aug 12 18:26:33 CEST 2006

tomer filiba wrote:
>>>> a={1:2, 3:4}
>>>> [] in a
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> TypeError: list objects are unhashable
> imo, the expression should just evaluate to False instead of raising an
> exception. it's a question of semantics -- i asked whether the object
> (a list, in this case) is contained in the dict. i didn't ask whether
> it's hashable or not.

However, if it isn't hashable, asking whether it is in a dict is very
likely to be a programming error.

David Hopwood <david.nospam.hopwood at blueyonder.co.uk>

More information about the Python-Dev mailing list