Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'float': 0.05; 'broken.': 0.09; 'iterate': 0.09; '23,': 0.16; 'compare.': 0.16; 'distinct': 0.16; 'iterable': 0.16; 'key?': 0.16; 'keys.': 0.16; 'py3': 0.16; 'subject:key': 0.16; 'unequal': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'compare': 0.20; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'example': 0.25; 'question': 0.26; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.28; 'decimal': 0.29; 'dictionary': 0.29; 'objects': 0.29; 'int': 0.33; 'equal': 0.34; 'subject:?': 0.34; 'received:google.com': 0.34; 'useful': 0.35; 'could': 0.35; 'to:addr:python-list': 0.35; 'sometimes': 0.35; 'but': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'tue,': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'determine': 0.61; 'simple': 0.61; 'avoid': 0.61; 'fundamental': 0.66; 'dict.': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=vk4kYrsqFEFHiQ9ro7kfyWQXvODL3YtCfmG3Hs8EtEE=; b=thXgaMpCJr1uQivWp3XH0L2gdCBRdRsGjVccPHSjQmzlGmXIzRuz40jrkmq/EpbJqc eW0TQH+cOSxR81CO1GsqVz/oPDvDxQN/Y1B3VoZ2lEgs5h+1X1rrEQTybzL1NQiuL2zc YLwVy8XkKeynNtSHBl8ZJC8hjKI0fHyYb6+8sVLaBsO53/u08oin3vQfCnyCwWHtCaz2 Lu5dRTFIe4DX5QFBGrm/rhM+UdCiRpie0oTyY16STBXI91Ly5t/b2oE6eeXbtmJjLik+ BxwyyHPuXRQ/4sY5bFdDsgP7512jArvNyPb9aorJhnQ02Z0uqxPLQz8IrCK7//ap9SxB PuTw== X-Received: by 10.129.94.7 with SMTP id s7mr433175ywb.111.1435128686240; Tue, 23 Jun 2015 23:51:26 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87a8vpykwq.fsf@nightsong.com> References: <851th2t05t.fsf@benfinney.id.au> <87a8vpykwq.fsf@nightsong.com> From: Ian Kelly Date: Wed, 24 Jun 2015 00:50:46 -0600 Subject: Re: Looking up a dictionary _key_ by key? To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435128694 news.xs4all.nl 2861 [2001:888:2000:d::a6]:52215 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93065 On Tue, Jun 23, 2015 at 7:06 PM, Paul Rubin wrote: > Chris Angelico writes: >>> Would I have to do an O(n) search to find my key? >> Iterate over it - it's an iterable view in Py3 - and compare. > > I think the question was whether the O(n) search could be avoided, not > how to do it. I don't see a way to avoid it. There is fundamental > brokenness in having unequal objects compare as equal, and the breakage > messes up the dictionary when those objects are used as keys. I don't think that it's fundamentally broken. A simple example would be the int 3, vs. the float 3, vs. the Decimal 3. All of them compare equal to one another, but they are distinct values, and sometimes it might be useful to be able to determine which one is actually a key in the dict.