Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5863
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ethan@stoneleaf.us> |
| 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; '>>>>': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'hash': 0.09; 'message- id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'url:dev': 0.09; '~ethan~': 0.09; 'this:': 0.10; 'def': 0.12; 'wrote:': 0.14; 'differently:': 0.16; 'equal,': 0.16; 'furman': 0.16; 'python3:': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'cc:addr:python-list': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'trying': 0.23; 'objects': 0.23; 'somebody': 0.25; 'compare': 0.26; 'example': 0.27; "i'm": 0.27; 'class': 0.29; 'cc:addr:python.org': 0.30; 'equal': 0.31; "isn't": 0.33; '...': 0.34; 'thinking': 0.34; 'header:User-Agent:1': 0.35; 'several': 0.36; 'url:docs': 0.37; 'two': 0.37; 'url:python': 0.38; 'hoping': 0.38; 'url:org': 0.38; 'but': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'said': 0.39; 'happen': 0.60; 'received:websitewelcome.com': 0.67; 'received:69.93': 0.67; '13)': 0.84 |
| Date | Fri, 20 May 2011 10:57:42 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| User-Agent | Thunderbird 1.5.0.10 (Windows/20070221) |
| MIME-Version | 1.0 |
| To | Peter Otten <__peter__@web.de> |
| Subject | Re: hash values and equality |
| References | <4DD2C2A5.3080403@stoneleaf.us> <BANLkTimvzZeN5dmm2xHP5xV8Kpw2Nb9kuQ@mail.gmail.com> <4DD2D89D.4000303@stoneleaf.us> <BANLkTintqgBLFtBx8+1b+R10nywuKdKHOw@mail.gmail.com> <4DD2F661.2050005@stoneleaf.us> <BANLkTikx8U4jWwLXXazpmtsL6MasDmyVyg@mail.gmail.com> <BANLkTi=_GqrNntRU7pv7x=kj3gHurk-Gaw@mail.gmail.com> <mailman.1822.1305870290.9059.python-list@python.org> <ir5292$3md$1@solani.org> |
| In-Reply-To | <ir5292$3md$1@solani.org> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - gator410.hostgator.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - stoneleaf.us |
| X-Source | |
| X-Source-Args | |
| X-Source-Dir | |
| X-Source-Sender | mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1706 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1846.1305913522.9059.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305913522 news.xs4all.nl 49038 [::ffff:82.94.164.166]:38039 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5863 |
Show key headers only | View raw
Peter Otten wrote:
> Ethan Furman wrote:
>
>> Several folk have said that objects that compare equal must hash equal,
>> and the docs also state this
>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__
>>
>> I'm hoping somebody can tell me what horrible thing will happen if this
>> isn't the case? Here's a toy example of a class I'm thinking of writing
>> that will compare equal with int's, but hash differently:
>>
>> --> class Wierd():
>> ... def __init__(self, value):
>> ... self.value = value
>> ... def __eq__(self, other):
>> ... return self.value == other
>> ... def __hash__(self):
>> ... return hash((self.value + 13) ** 3)
>> ...
>
> Try this:
>
>>>> d = {Wierd(1): 0}
>>>> 1 in d
> False
>>>> 1 in d.keys()
> True
>
My apologies -- I'm trying this in Python3:
--> two in d
True
--> two in d.keys()
True
-->
--> 2 in d
True
--> 2 in d.keys()
True
~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
hash values and equality Ethan Furman <ethan@stoneleaf.us> - 2011-05-19 22:43 -0700
Re: hash values and equality Peter Otten <__peter__@web.de> - 2011-05-20 08:38 +0200
Re: hash values and equality Ethan Furman <ethan@stoneleaf.us> - 2011-05-20 10:57 -0700
Re: hash values and equality Peter Otten <__peter__@web.de> - 2011-05-20 22:25 +0200
Re: hash values and equality Ethan Furman <ethan@stoneleaf.us> - 2011-05-20 14:48 -0700
Re: hash values and equality Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-05-20 08:33 +0200
Re: hash values and equality MRAB <python@mrabarnett.plus.com> - 2011-05-20 16:50 +0100
Re: hash values and equality Chris Angelico <rosuav@gmail.com> - 2011-05-21 02:20 +1000
Re: hash values and equality Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-20 11:59 -0600
Re: hash values and equality Ethan Furman <ethan@stoneleaf.us> - 2011-05-20 11:38 -0700
Re: hash values and equality Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-21 20:24 +1200
Re: hash values and equality Peter Otten <__peter__@web.de> - 2011-05-21 11:24 +0200
Re: hash values and equality Christian Heimes <lists@cheimes.de> - 2011-05-20 21:01 +0200
Re: hash values and equality MRAB <python@mrabarnett.plus.com> - 2011-05-20 21:17 +0100
Re: hash values and equality Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-21 00:47 +0000
Re: hash values and equality MRAB <python@mrabarnett.plus.com> - 2011-05-21 02:02 +0100
Re: hash values and equality Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-21 01:55 +0000
Re: hash values and equality John Nagle <nagle@animats.com> - 2011-05-21 15:55 -0700
Re: hash values and equality Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2011-05-22 01:07 +0200
Re: hash values and equality Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-22 00:24 +0000
csiph-web