Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37698
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.055 |
| X-Spam-Evidence | '*H*': 0.89; '*S*': 0.00; '(1,': 0.09; 'subject:set': 0.09; '(say': 0.16; 'subject:object': 0.16; 'x).': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'solution.': 0.18; '>>>': 0.18; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'set.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'seemingly': 0.29; 'objects': 0.29; 'fri,': 0.30; 'could': 0.32; 'true.': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'problem,': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'containing': 0.61; 'dear': 0.66; '2013': 0.84; 'dict.': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=Bz0xB1IN71RPM3csg6rj/jBr8UzFcBEQhqnTh8wnXT4=; b=cNOkLhHaWER5qMCUAxKcjlJGRHlLDRkYiK5AS8+a49fwAXR/07hbfTOOXD1m1lrLO8 b37VPLwz9WcS5P0kMbHDBg7ZuN9diFHZHncLMNV5O1X9le+1ZsOvFq2V/956PjK4bJit fKOfizGKTbQlSqPNHCmnmhhZm6BK4ak40gB7vHNgH41wLzachCNV+auNWAARafx2QoTC iiFhQ1GHRiKsrPR/GJ+kngacvjb6cTOj7T/SFb45fV6YYIAhuaT9ldb5rqNNbyXXYFzY bPfb63u+JuphxYLfl5rONdlcxVcYhD4lpUuXnEZqsmkaxNb28XQh2rgwHQxL2iLYxvaj gmPw== |
| X-Received | by 10.68.212.167 with SMTP id nl7mr18199087pbc.12.1359156680614; Fri, 25 Jan 2013 15:31:20 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com> |
| References | <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Fri, 25 Jan 2013 16:30:50 -0700 |
| Subject | Re: Retrieving an object from a set |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1058.1359156688.2939.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359156688 news.xs4all.nl 6923 [2001:888:2000:d::a6]:57715 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37698 |
Show key headers only | View raw
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