Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37702

Re: Retrieving an object from a set

Date 2013-01-25 18:56 -0500
From Dave Angel <d@davea.name>
Subject Re: Retrieving an object from a set
References <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1062.1359158206.2939.python-list@python.org> (permalink)

Show all headers | View raw


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 in S which is equal to x.  My
> problem is how to retrieve y, without going through the whole set.
> Here is a simple illustration with tuples (my actual scenario is not
> with tuples but with a custom class):
>
>>>> y = (1, 2, 3) # This is the 'hidden object'
>>>> S = set([y] + range(10000))
>>>> x = (1, 2, 3)
>>>> x in S
> True
>>>> x is y
> False
>
> I haven't found y.

Baloney.  You've got the item y which is equal to x, not identical to x. 
  So just what did you expect?  "is" is the wrong comparator.

What exactly is your problem?


-- 
DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Retrieving an object from a set Dave Angel <d@davea.name> - 2013-01-25 18:56 -0500

csiph-web