insert unique data in a list
Lie Ryan
lie.1296 at gmail.com
Mon Dec 14 14:34:57 EST 2009
On 12/15/2009 4:13 AM, mattia wrote:
>> >
>> > of course it is broken as long as it uses it's instance id. i added this
>> > to notify that unhashable can become hashable implementing __hash__
>> > inside the class. which probably set to None by default.
> Ok, nice example, but I believe that using id() as the hash function can
> lead to unexpected collisions.
For dict and set to work correctly, the hash function must conform to
the contract that:
- if A == B then hash(A) == hash(B)
If the id() of two objects differ but their content equal (i.e. they are
two equivalent, but distinct object), they should have the same hash. If
id() is used for the hash of an arbitrary object, the contract will be
broken unless you define A == B in terms of id(A) == id(B).
More information about the Python-list
mailing list