Re: (objects as) mutable dictionary keys
From: John Roth (newsgroups_at_jhrothjr.com)
Date: 01/14/05
- Next message: Christopher De Vries: "Re: Integration with java"
- Previous message: Fredrik Lundh: "Re: python and macros (again) [Was: python3: 'where' keyword]"
- In reply to: Peter Maas: "Re: (objects as) mutable dictionary keys"
- Next in thread: Steven Bethard: "Re: (objects as) mutable dictionary keys"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Jan 2005 11:09:06 -0600
"Peter Maas" <peter@somewhere.com> wrote in message
news:cs8a7e$t87$1@swifty.westend.com...
>I have summarized the discussion about the usability of lists (and
> and other mutable types) as dictionary keys and put it into the
> Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
>
> This summary might be used as a reference should the 'mutable
> dictionary keys' issue come up again in c.l.py.
The last piece has an incorrect conclusion. Lists are not safe
_because_ the cmp function is NOT a compare of id(list), but
is based on list contents, which can change at any time.
It should also be emphasized that the default instance hash
and cmp functions quoted make it impossible for two different
instances to compare equal, thus there is no reason to store them
as dictionary keys: it's simpler to make the value an attribute of
the instance and bypass the additional complexity of the dictionary.
John Roth
>
> --
> -------------------------------------------------------------------
> Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
> E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
> -------------------------------------------------------------------
>
- Next message: Christopher De Vries: "Re: Integration with java"
- Previous message: Fredrik Lundh: "Re: python and macros (again) [Was: python3: 'where' keyword]"
- In reply to: Peter Maas: "Re: (objects as) mutable dictionary keys"
- Next in thread: Steven Bethard: "Re: (objects as) mutable dictionary keys"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|