Customizing sequence types
Mr.SpOOn
mr.spoon21 at gmail.com
Tue Nov 18 05:01:57 EST 2008
On Tue, Nov 18, 2008 at 1:59 AM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar> wrote:
> Yes, __cmp__ is gone in 3.0
> You said you wrote __cmp__ the same as __eq__ and that's wrong, they return
> different results. Try something like this (untested):
>
> class X:
> def __init__(self, a): self.a = a
> def __cmp__(self, other): return cmp(self.a, other.a)
> def __hash__(self): return hash(self.a)
>
> x1 = X(1)
> x2 = X(2)
> x3 = X(3)
> x4 = X(1)
>
> print len(set([x1, x2, x3, x4]) # should be 3!
Yes, this works. Thanks.
More information about the Python-list
mailing list