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


Groups > comp.lang.python > #93065

Re: Looking up a dictionary _key_ by key?

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 <ian.g.kelly@gmail.com>
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 <CAGGBd_pd9SA7SczanGARFr-+Z9SxP9Mkhfo-RivpcJLrnuexng@mail.gmail.com> <851th2t05t.fsf@benfinney.id.au> <CAGGBd_qaNC38Yg0u_b8+qBAckq6FRTZMxbWwuzV=MUYE_=ZzDw@mail.gmail.com> <mailman.3.1435107726.3674.python-list@python.org> <87a8vpykwq.fsf@nightsong.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 24 Jun 2015 00:50:46 -0600
Subject Re: Looking up a dictionary _key_ by key?
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7.1435128694.3674.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Tue, Jun 23, 2015 at 7:06 PM, Paul Rubin <no.email@nospam.invalid> wrote:
> Chris Angelico <rosuav@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Looking up a dictionary _key_ by key? Chris Angelico <rosuav@gmail.com> - 2015-06-24 11:02 +1000
  Re: Looking up a dictionary _key_ by key? Paul Rubin <no.email@nospam.invalid> - 2015-06-23 18:06 -0700
    Re: Looking up a dictionary _key_ by key? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-24 00:50 -0600
      Re: Looking up a dictionary _key_ by key? Marko Rauhamaa <marko@pacujo.net> - 2015-06-24 09:55 +0300
    Re: Looking up a dictionary _key_ by key? Laura Creighton <lac@openend.se> - 2015-07-05 08:25 +0200

csiph-web