Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'algorithm': 0.03; 'mrab': 0.05; 'python': 0.09; '3.0,': 0.09; 'calculating': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:set': 0.09; '2.7.3': 0.16; 'curious.': 0.16; 'length,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'set:': 0.16; 'subject:object': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'sets': 0.23; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'header:X-Complaints-To:1': 0.28; '>>>>': 0.29; 'maybe': 0.29; 'turns': 0.33; 'to:addr:python-list': 0.33; 'false': 0.35; 'there': 0.35; 'received:org': 0.36; 'smaller': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'more': 0.63; 'jul': 0.65 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Retrieving an object from a set Date: Sat, 26 Jan 2013 09:10:24 +0100 Organization: None References: <51031922.2020104@mrabarnett.plus.com> <510345FA.5000607@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849698.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359187813 news.xs4all.nl 6938 [2001:888:2000:d::a6]:33315 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37716 Vito De Tullio wrote: > MRAB wrote: > >> It turns out that both S & {x} and {x} & S return {x}, not {y}. > > curious. > > $ python > Python 2.7.3 (default, Jul 3 2012, 19:58:39) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = (1,2,3) >>>> y = (1,2,3) >>>> s = set([y]) >>>> (s & set([x])).pop() is y > False >>>> (set([x]) & s).pop() is y > True > > maybe it's implementation-defined? I think the algorithm looks for the smaller set: >>> set(range(5)) & set(map(float, range(10))) set([0, 1, 2, 3, 4]) >>> set(range(10)) & set(map(float, range(5))) set([0.0, 1.0, 2.0, 3.0, 4.0]) You have two sets of the same length, so there is no advantage in swapping them before calculating the intersection.