objects as mutable dictionary keys

Peter Maas peter at somewhere.com
Tue Dec 28 00:04:40 CET 2004

Steven Bethard schrieb:
> If lists were hashable, new programmers to Python would almost certainly 
> make mistakes like:
> py> d = {[1, 2, 3]: 'abc'}

 > The coder here almost certainly *doesn't* want that list to be compared
 > by id.  The only way to get a binding for that list would be using the
 > dict's keys or __iter__ methods.

That's what I meant when I said that for lists id() doesn't make sense
as hash because of the list literals.

For user defined objects id() can be used as hash because there are
no literals for user defined objects.

Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')

More information about the Python-list mailing list