Re: Get item from set

2009-04-29 Thread Raymond Hettinger
[bearophileh...@lycos.com] > But some other times you may accept to change the class and the set/ > dict, making it tell apart the keys only when they are different > object: > > class Some(object): >     def __init__(self, y): >         self._y = y >     def __eq__(self, other): >         return s

Re: Get item from set

2009-04-29 Thread Aahz
In article , Peter Otten <__pete...@web.de> wrote: >Aahz wrote: >> In article , >> Peter Otten <__pete...@web.de> wrote: >>>Aahz wrote: In article , Peter Otten <__pete...@web.de> wrote: > >Here's a trick to find the actual element. I think Raymond Hettinger >posted an impl

Re: Get item from set

2009-04-29 Thread Peter Otten
Aahz wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >>Aahz wrote: >>> In article , >>> Peter Otten <__pete...@web.de> wrote: Here's a trick to find the actual element. I think Raymond Hettinger posted an implementation of this idea recently, but I can't find it at >>>

Re: Get item from set

2009-04-29 Thread Aahz
In article , Peter Otten <__pete...@web.de> wrote: >Aahz wrote: >> In article , >> Peter Otten <__pete...@web.de> wrote: >>> >>>Here's a trick to find the actual element. I think Raymond Hettinger >>>posted an implementation of this idea recently, but I can't find it at the >>>moment. >> >> Your

Re: Get item from set

2009-04-29 Thread Peter Otten
Aahz wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >> >>Here's a trick to find the actual element. I think Raymond Hettinger >>posted an implementation of this idea recently, but I can't find it at the >>moment. > > Your code is inverted from Raymond's: I can't see the inversion

Re: Get item from set

2009-04-27 Thread Terry Reedy
Johannes Bauer wrote: Hi group, I have a very simple about sets. This is a minimal example: #!/usr/bin/python class x(): def __init__(self, y): self.__y = y def __eq__(self, other): return self.__y == other.__y def __hash__(self):

Re: Get item from set

2009-04-27 Thread Aahz
In article , Peter Otten <__pete...@web.de> wrote: > >Here's a trick to find the actual element. I think Raymond Hettinger posted >an implementation of this idea recently, but I can't find it at the moment. Your code is inverted from Raymond's: http://code.activestate.com/recipes/499299/ class

Re: Get item from set

2009-04-27 Thread Johannes Bauer
Peter Otten schrieb: > class Grab: > def __init__(self, value): > self.search_value = value > def __hash__(self): > return hash(self.search_value) > def __eq__(self, other): > if self.search_value == other: > self.actual_value = other > r

Re: Get item from set

2009-04-27 Thread Johannes Bauer
Johannes Bauer schrieb: > Is there something like the "getelement" function? How can I do what I want? One side note: The obvious trivial solution: def findset(s, e): for i in s: if e == i: return i return None is because of its complexity

Re: Get item from set

2009-04-26 Thread bearophileHUGS
Peter Otten: > [...] I think Raymond Hettinger posted > an implementation of this idea recently, but I can't find it at the moment. > [...] > class Grab: >     def __init__(self, value): >         self.search_value = value >     def __hash__(self): >         return hash(self.search_value) >     def

Re: Get item from set

2009-04-26 Thread Peter Otten
Johannes Bauer wrote: > I have a very simple about sets. This is a minimal example: > The problem is: two instances of x() are equal (__eq__ returns true), > but they are not identical. I have an equal element ("z"), but want to > get the *actual* element ("a") in the set. I.d. in the above examp

Get item from set

2009-04-26 Thread Johannes Bauer
Hi group, I have a very simple about sets. This is a minimal example: #!/usr/bin/python class x(): def __init__(self, y): self.__y = y def __eq__(self, other): return self.__y == other.__y def __hash__(self): return hash(self