Re: Retrieving an object from a set

2013-01-26 Thread Peter Otten
Vito De Tullio wrote: > MRAB wrote: > >> It turns out that both S & {x} and {x} & S return {x}, not {y}. > > curious. > > $ python > Python 2.7.3 (default, Jul 3 2012, 19:58:39) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x = (1,2,3) >>

Re: Retrieving an object from a set

2013-01-25 Thread Vito De Tullio
MRAB wrote: > It turns out that both S & {x} and {x} & S return {x}, not {y}. curious. $ python Python 2.7.3 (default, Jul 3 2012, 19:58:39) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = (1,2,3) >>> y = (1,2,3) >>> s = set([y]) >>> (s & se

Re: Retrieving an object from a set

2013-01-25 Thread Steven D'Aprano
Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S

Re: Retrieving an object from a set

2013-01-25 Thread MRAB
On 2013-01-26 00:26, Ian Kelly wrote: On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: You could first limit the search to only those which it could be: S & set([y]) A search would be: f = [m for m in S & set([y]) if m is y][0] f is y True But in practice he won't have y, only x. So tha

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: > You could first limit the search to only those which it could be: > > S & set([y]) > > A search would be: > f = [m for m in S & set([y]) if m is y][0] f is y > True But in practice he won't have y, only x. So that would have to be: >>

Re: Retrieving an object from a set

2013-01-25 Thread Dave Angel
On 01/25/2013 06:14 PM, Arnaud Delobelle wrote: Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y

Re: Retrieving an object from a set

2013-01-25 Thread Ethan Furman
On 01/25/2013 03:14 PM, Arnaud Delobelle wrote: I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equa

Re: Retrieving an object from a set

2013-01-25 Thread MRAB
On 2013-01-25 23:14, Arnaud Delobelle wrote: Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:30 PM, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: >> Dear Pythoneers, >> >> I've got a seemingly simple problem, but for which I cannot find a >> simple solution. >> >> I have a set of objects (say S) containing an object which is equal t

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true.

Retrieving an object from a set

2013-01-25 Thread Arnaud Delobelle
Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to ret