insert unique data in a list
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Sun Dec 13 22:42:26 EST 2009
On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote:
> this makes the set type hashable.
>
> class Set(set):
> __hash__ = lambda self: id(self)
That's a *seriously* broken hash function.
>>> key = "voila"
>>> d = { Set(key): 1 }
>>> d
{Set(['i', 'a', 'l', 'o', 'v']): 1}
>>> d[ Set(key) ]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: Set(['i', 'a', 'l', 'o', 'v'])
--
Steven
More information about the Python-list
mailing list