tuple.__hash__()
Peter Otten
__peter__ at web.de
Tue Jan 6 04:14:58 EST 2004
Thomas Guettler wrote:
> I want to unique a list of tuples. Since
> __hash__ returns a 32 bit integer, there
> could be a situtation where two different tupples
> return the same value.
Maybe you can decorate/uniquify/undecorate?
>>> items = [t1, t2, t1, t1]
>>> di = [(id(i), i) for i in items]
>>> from sets import Set
>>> si = Set(di)
>>> ui = [i[1] for i in si]
>>> ui
[(1, 2, 3), (1, 2, 3)]
> Is there a dictionary type which uses __cmp__() like
> btrees in the standard library?
I don't understand. For the above example an algorithm based on __cmp__()
would return a list with a single item which does not seem to be what you
want.
Peter
More information about the Python-list
mailing list