[Python-ideas] An identity dict
Lie Ryan
lie.1296 at gmail.com
Sun May 30 13:07:52 CEST 2010
On 05/30/10 20:34, Antoine Pitrou wrote:
> On Sun, 30 May 2010 03:27:53 +0000 (UTC)
> Benjamin Peterson <benjamin at python.org>
> wrote:
>> In the spirit of collections.OrderedDict and collections.defaultdict, I'd like
>> to propose collections.identitydict. It would function just like a normal
>> dictionary, but ignore hash values and comparison operators and merely lookup
>> keys based on the key's id().
>
> Perhaps it would be more useful to add a generic
> collections.keyfuncdict, taking a function which applied to a key
> gives the real key value used for lookups.
> Your identity dict would be created as:
> d = collections.keyfuncdict(id)
>
> But of course, you can just use a normal dict:
> d = {}
> d[id(key)] = key, value
>
> (actually, this could be how a collections.keyfuncdict gets implemented)
+1 on this
More information about the Python-ideas
mailing list