Dictionary, keys and alias
Terry Reedy
tjreedy at udel.edu
Tue Jul 19 13:52:01 EDT 2005
"Steven D'Aprano" <steve at REMOVETHIScyber.com.au> wrote in message
news:pan.2005.07.19.13.56.18.857714 at REMOVETHIScyber.com.au...
> On Tue, 19 Jul 2005 10:20:04 +0200, Glauco wrote:
>
>>> The only niggly worry I have is I'm not sure when hash can be used,
>>> when
>>> it is unique, or even if is it guaranteed to be unique.
>>>
>>
>> Thank Steve, the idea was the same...
>> but yours using hash is much elegant.
>
> I'm still worried about hash of two unrelated objects returning the same
> value.
>
> Another implementation is to keep a hidden attribute of the object, and
> initialise it to the integer 0. Instead of using hash(key), you use the
> current value of the integer, then increment the integer by one.
>
> This is guaranteed to be unique, no matter what.
id(ob) is already guaranteed to be a unique integer while ob exists. So,
if I understand the goal, map possibly-multiple-keys each to id and id to
ob.
Terry J. Reedy
More information about the Python-list
mailing list