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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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