Dictionary, keys and alias

Steven D'Aprano steve at REMOVETHIScyber.com.au
Tue Jul 19 09:56:19 EDT 2005


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.


-- 
Steven.




More information about the Python-list mailing list