Re: Dictionary, keys and alias

2005-07-19 Thread Glauco
Steven D'Aprano wrote: On Mon, 18 Jul 2005 12:17:37 +0200, Glauco wrote: I want to insert a concept of alias in a dict_based class. The idea is to have a facoltative name in the same dict that correspond at the same value. With this alias i can change original value. example: mydict['a']

Re: Dictionary, keys and alias

2005-07-19 Thread Steven D'Aprano
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

Re: Dictionary, keys and alias

2005-07-19 Thread Cyril Bazin
Glauco, Be careful if you decide to use hash. There is possibility of bugs due to that approach, (if hash(x) == hash(y) and x != y). Even if the probability of bug is near 0, your computer will certainly recall you what is the murphy law. If I were you, I would prefer another approach. Cyril

Re: Dictionary, keys and alias

2005-07-19 Thread Terry Reedy
Steven D'Aprano [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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

Re: Dictionary, keys and alias

2005-07-18 Thread Peter Hansen
Glauco wrote: I want to insert a concept of alias in a dict_based class. ... Any suggestion ? Yes, in future don't attempt to start a new thread using Reply unless you are happy not having your post read by all those who have already killed the thread to which you replied. Anyone who was not

Re: Dictionary, keys and alias

2005-07-18 Thread Steven D'Aprano
On Mon, 18 Jul 2005 12:17:37 +0200, Glauco wrote: I want to insert a concept of alias in a dict_based class. The idea is to have a facoltative name in the same dict that correspond at the same value. With this alias i can change original value. example: mydict['a'] = 1 I must define

Re: Dictionary, keys and alias

2005-07-18 Thread Cyril Bazin
I think hash doesn't guarantee the unicity of the result. But, it should avoid the collisions... foo = foo hash(foo) -740391237 hash(-740391237) -740391237 I think it's like some kind md5sum... I propose this solution: --- from