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


Groups > comp.lang.python > #75477

Re: Dict when defining not returning multi value key error

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'subject:error': 0.03; 'subject:not': 0.03; '(at': 0.04; 'calculating': 0.09; 'check,': 0.09; 'encode': 0.09; 'imply': 0.09; 'way:': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'different,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashes': 0.16; 'implies': 0.16; 'looked-up': 0.16; "object's": 0.16; 'skips': 0.16; 'subject:key': 0.16; 'subject:when': 0.16; 'wrote:': 0.18; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'logical': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; 'first,': 0.26; 'least': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'equality': 0.31; 'large.': 0.31; 'steven': 0.31; 'yes.': 0.31; 'says': 0.33; 'fri,': 0.33; 'classes': 0.35; 'equal': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'should': 0.36; 'pm,': 0.38; 'does': 0.39; 'system.': 0.39; 'entire': 0.61; 'different': 0.65; 'fact,': 0.69; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gOAqa7pBmKO8HIoKRNHNBIwcQsf38332nUk9rafzEWU=; b=HfXvOI6Pbe2JRiKGqsrsof/Us/p5UbQwhLCoapy7Sdfgw2TQ+KrYjz5tSvHhBqgelu hhaMxNPxK3HNFux9X69YeiPQfjqlkbJKeGaOQslUQa9kZeOy8F611DdnQ22JjU4ak7yX WJiqE6Eussn+YFOL6bP644XPwqtVYDyVAqy6NKZT1mCaBJ1BodEqDYZlWioI2tVb5/35 r4OD4wBfzaFaQ/6pDK48EkSB/wC7c4OhbYMYlZZ6uvuAEFBDvaBshWOg1A0u1G1tTXEm MA1dEI6ZHC7dN2eJvDpZKfAozvPw6UDNNJf7l+OQlNbb0g+4uJLHS/Yd/ETXrl1bbHJO UAXQ==
MIME-Version 1.0
X-Received by 10.43.96.65 with SMTP id cf1mr7304227icc.26.1406901477146; Fri, 01 Aug 2014 06:57:57 -0700 (PDT)
In-Reply-To <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com>
References <CAFBK5a-hjukHaHOim4tL_RerXiHsFP03eaQoN42yGfeCJ9NZPg@mail.gmail.com> <CAGGBd_riruS0nRM9+o+1dz=jVZgYOo09qX97P+LWK5Nu6HTYRw@mail.gmail.com> <mailman.12501.1406862741.18130.python-list@python.org> <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <mailman.12503.1406866676.18130.python-list@python.org> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com>
Date Fri, 1 Aug 2014 23:57:57 +1000
Subject Re: Dict when defining not returning multi value key error
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <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.12512.1406901485.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406901485 news.xs4all.nl 2868 [2001:888:2000:d::a6]:35528
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75477

Show key headers only | View raw


On Fri, Aug 1, 2014 at 11:31 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Yes. Although Python promises (at least for classes in the standard
> library) that x == y should imply that hash(x) == hash(y), it says
> nothing about the other way:
>
> x == y implies that hash(x) == hash(y)

This is the entire point of the hashing system. If equal values can
hash differently, why bother calculating the hashes?

Or if you prefer, the point of hashing is the logical converse of the
above: hash(x) != hash(y) implies that x != y. If the hashes are
different, you can skip the equality check, ergo you can build a data
type that claims to search for the key that == the looked-up key, but
actually does a much faster hash check first, and skips everything
with a different hash.

> but hash(x) == hash(y) does NOT imply that x == y.
>

Hello, pigeonhole principle :) If this were false - that is, if equal
hashes DID imply equal objects - it would be necessary to completely
encode an object's state in its hash, and hashes would be impossibly
large. This would, in fact, destroy their value completely.

ChrisA

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


Thread

Re: Dict when defining not returning multi value key error Dan Stromberg <drsalists@gmail.com> - 2014-07-31 20:12 -0700
  Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-01 04:04 +0000
    Re: Dict when defining not returning multi value key error Ben Finney <ben+python@benfinney.id.au> - 2014-08-01 14:17 +1000
      Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-01 13:31 +0000
        Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-01 23:57 +1000
          Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-01 18:39 +0300
            Re: Dict when defining not returning multi value key error Terry Reedy <tjreedy@udel.edu> - 2014-08-01 17:42 -0400
            Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 09:57 +1000
              Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-02 09:41 +0300
                Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-02 10:06 +0300
                Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 20:58 +1000
            Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-02 11:47 +1000
              Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 12:13 +1000

csiph-web