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


Groups > comp.lang.python > #75459

Re: Dict when defining not returning multi value key error

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Dict when defining not returning multi value key error
Date 2014-08-01 14:17 +1000
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>
Newsgroups comp.lang.python
Message-ID <mailman.12503.1406866676.18130.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> On Thu, 31 Jul 2014 20:12:12 -0700, Dan Stromberg wrote:
>
> > I removed some quotes, and noticed that 1 and 1.0 hash the same.
> > That's a bit unexpected, but I suppose it's not completely
> > unreasonable.

I would expect it, for the reasons Steven explains. Why is it
unexpected?

> You should expect that two equal objects should hash to the same value
> in different versions of Python, or even from one run of Python to the
> next.

I suspect there's a “not” missing there.

To be explicit: You should not expect any particular comparisons to hold
true for hash values between different Python versions, or even from one
run to the next.

Only those promises made or logically implied in the API should be
expected. Implementation details should be expected to break assumptions
— in other words, don't depend on any particular behaviour of an
implementation detail.

If you expect the hash valuesto be the same, you're making a mistake; if
you expect the hash values to be different, you're making a mistake.

The correct attitude, with regard to implementation details, is to
expect uncertainty and not assume anything :-)

-- 
 \      “Natural catastrophes are rare, but they come often enough. We |
  `\   need not force the hand of nature.” —Carl Sagan, _Cosmos_, 1980 |
_o__)                                                                  |
Ben Finney

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