Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37700
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; '(1,': 0.09; 'be:': 0.09; 'subject:set': 0.09; '(say': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'illustration': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:object': 0.16; 'x).': 0.16; 'wrote:': 0.17; 'solution.': 0.18; '>>>': 0.18; 'tuples': 0.22; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'set.': 0.27; 'actual': 0.28; '(my': 0.29; '>>>>': 0.29; 'seemingly': 0.29; 'objects': 0.29; 'received:84': 0.32; 'could': 0.32; 'true.': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'false': 0.35; 'problem,': 0.35; 'there': 0.35; 'but': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'containing': 0.61; 'first': 0.61; 'here': 0.65; 'limit': 0.65; 'dear': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:python.org': 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.0 cv=HO4d4PRv c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=mQ9LD9t0MLYA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=-KSjhMp78moA:10 a=854DXGBUOeO-vHbHjCAA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 |
| X-AUTH | mrabarnett:2500 |
| Date | Fri, 25 Jan 2013 23:45:38 +0000 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Retrieving an object from a set |
| References | <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com> |
| In-Reply-To | <CAJ6cK1b=F5JXL=FN0qouS-idbE8xnVURm0ZZrZ8-DW2xbLNErg@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| 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.1060.1359157543.2939.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359157543 news.xs4all.nl 6934 [2001:888:2000:d::a6]:35149 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37700 |
Show key headers only | View raw
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 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
>
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Retrieving an object from a set MRAB <python@mrabarnett.plus.com> - 2013-01-25 23:45 +0000
csiph-web