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


Groups > comp.lang.python > #37702

Re: Retrieving an object from a set

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 <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'problem?': 0.07; '(1,': 0.09; 'subject:set': 0.09; '"is"': 0.16; '(say': 0.16; 'illustration': 0.16; 'subject:object': 0.16; 'x).': 0.16; 'wrote:': 0.17; 'solution.': 0.18; 'tuples': 0.22; "haven't": 0.23; "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; 'true.': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'wrong': 0.34; 'false': 0.35; 'problem,': 0.35; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'item': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; "you've": 0.61; 'containing': 0.61; 'here': 0.65; 'dear': 0.66; 'received:74.208': 0.71
Date Fri, 25 Jan 2013 18:56:14 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 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-Provags-ID V02:K0:cFD9QfZ2jz+SRaEg6Xu0OKkMez16NIJUT4Fka4V/57J RK9CggPlG6g1Eh8lHPd0aar7AA1bzFQueEK1VaXcJHW0WGalrR P8TwLK48rlk7iPK0DvkLS+gToURmB0PARNmTXh1xJmnUrAOu1g Chaag95QuqqotzzzWyXcgn9ksR6tdq5vPohm3hv8UPh4/hoeFU kmhVE5yVr0RladAt4t8ErJR+jq6z4RHJtLr8ndrHexNnInGk4m xFBwe7Vm4PTRTKyq9+LEtjcGoP431mxh8JRcsfjgbyiwyvQHj+ BaI+m+bCHvm6vv8UL29ly+q6mB802Bzok+xlj5CKJOiaQpWMQ= =
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.1062.1359158206.2939.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359158206 news.xs4all.nl 6907 [2001:888:2000:d::a6]:40739
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37702

Show key headers only | 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