[pyar] Duda acerca de sets
Terry Reedy
tjreedy en udel.edu
Dom Ene 29 07:07:23 ART 2012
On 1/29/2012 12:41 AM, Tordek wrote:
> Tenés que definir __hash__:
>
> def __hash__(self):
> return hash(self.id)
>
> De http://docs.python.org/library/sets.html:
>
> "[...] the requirements for set elements are the same as those for
> dictionary keys; namely, that the element defines both __eq__() and
> __hash__()."
Y sin definirlo, se usa object.__hash__(ob) == id(ob),
y id(o1) != id(o2).
--
Terry Jan Reedy
More information about the pyar
mailing list