Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37698
| References | <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2013-01-25 16:30 -0700 |
| Subject | Re: Retrieving an object from a set |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1058.1359156688.2939.python-list@python.org> (permalink) |
On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle <arnodel@gmail.com> 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.
You could use a dict.
>>> y = (1, 2, 3)
>>> S = {x: x for x in [y] + range(10000)}
>>> x = (1, 2, 3)
>>> x in S
True
>>> x is y
False
>>> S[x] is y
True
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Retrieving an object from a set Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-25 16:30 -0700
csiph-web