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


Groups > comp.lang.python > #16854

Re: adding elements to set

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder2.enfer-du-nord.net!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'bits': 0.07; 'subject:adding': 0.07; 'unexpected': 0.07; 'python': 0.08; 'subclasses': 0.09; 'am,': 0.12; 'def': 0.13; 'algorithm': 0.13; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:set': 0.16; 'type:': 0.16; 'unhashable': 0.16; 'this:': 0.16; 'wrote:': 0.18; '>>>': 0.18; '3.2': 0.18; '(most': 0.21; 'dec': 0.22; 'header:In-Reply- To:1': 0.22; 'changed': 0.23; 'ones.': 0.23; 'traceback': 0.24; '(in': 0.26; '(this': 0.28; 'message-id:@mail.gmail.com': 0.28; 'fine.': 0.29; 'idle': 0.29; 'class': 0.29; 'fewer': 0.30; 'hash': 0.30; 'typeerror:': 0.30; 'least': 0.30; 'value.': 0.32; 'comment': 0.32; "can't": 0.32; 'fri,': 0.34; 'to:addr:python- list': 0.34; 'last):': 0.34; 'however,': 0.36; 'file': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'skip:_ 10': 0.37; 'received:209.85': 0.38; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'according': 0.61; '2011': 0.61; 'easily.': 0.67; 'saw': 0.67; '__eq__(self,': 0.84; 'interesting,': 0.84; 'other):': 0.84; 'otten': 0.84; 'x):': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=rI/tO0WbYJgTe557asX8nCOgvSpeIhe+9WtyGYui1bE=; b=cXjapPT/3d0z97tQ2AA9cTTBMcYUQuWrdDfuaP2EQAIy/qT6YYZk/Q2NTFqNtj9OSL guWIFesLjauI6U7X33IwpowIO3OYW4JAVkn5P8D36efwzbd0hU0zMLeDo0zLwTyrgnRd 2K6jdoGj7k/sG79nMZYqaYc9byoUjDRnCKWgY=
MIME-Version 1.0
In-Reply-To <jbqsad$q2n$1@dough.gmane.org>
References <4EE0E72E.2040104@gmail.com> <CAPTjJmpm9xV21WaAsaO+PysuMa=oJ6avT4x-OJWKm2jgKttH1Q@mail.gmail.com> <jbqsad$q2n$1@dough.gmane.org>
Date Fri, 9 Dec 2011 04:37:18 +1100
Subject Re: adding elements to set
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.3437.1323365841.27778.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323365841 news.xs4all.nl 6938 [2001:888:2000:d::a6]:52624
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16854

Show key headers only | View raw


On Fri, Dec 9, 2011 at 4:32 AM, Peter Otten <__peter__@web.de> wrote:
> The only thing that has changed (in 2.7) is the algorithm to calculate the
> hash value. The bits are rotated to turn the four least significant bits
> into the most signicant ones. According to a comment in Objects/objects.c
> the change leads to fewer hash collisions.

Interesting, but what I saw was this:

>>> class C(object):

   def __init__(self, x):
       self.x = x

   def __eq__(self, other):
       return self.x == other.x

>>> s=set()
>>> c1=C(1)
>>> s.add(c1)
Traceback (most recent call last):
  File "<pyshell#163>", line 1, in <module>
    s.add(c1)
TypeError: unhashable type: 'C'

(This is in IDLE from Python 3.2 on Windows.)

However, s.add(object()) works fine. So subclasses don't get that.
Odd. Makes sense though - you can't get this unexpected behaviour as
easily.

ChrisA

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


Thread

Re: adding elements to set Chris Angelico <rosuav@gmail.com> - 2011-12-09 04:37 +1100
  Re: adding elements to set Duncan Booth <duncan.booth@invalid.invalid> - 2011-12-08 18:54 +0000
    Re: adding elements to set Terry Reedy <tjreedy@udel.edu> - 2011-12-08 21:33 -0500

csiph-web