hash values and equality
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat May 21 20:24:35 EDT 2011
On Sat, 21 May 2011 15:55:56 -0700, John Nagle wrote:
> On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote:
>
>> For that reason, it is generally useful to use immutable types like
>> integers, floats, strings and tuples thereof as keys. Since you can't
>> change them, you basically have the guarantee that they hash the same.
>
> Right. It's something of a lack that Python doesn't
> have user-defined immutable objects.
Although it's not that hard to write your own immutable (-ish) objects.
http://northernplanets.blogspot.com/2007/01/immutable-instances-in-python.html
Or see the Decimal and Fraction classes in the standard library.
--
Steven
More information about the Python-list
mailing list