xrange not hashable - why not?

Hans Nowak hans at zephyrfalcon.org
Sun Jan 25 19:28:16 EST 2004


Jeff Epler wrote:
> On Sun, Jan 25, 2004 at 07:06:31PM -0500, Hans Nowak wrote:
> 
>>So far, everybody who replied seems to agree or assumes that xrange indeed 
>>isn't hashable.  However:
> 
> [...]
> 
> It wasn't in older versions:
> $ python
> Python 2.2.2 (#1, Feb 24 2003, 19:13:11) 
> [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
>>>>hash(xrange(0))
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: unhashable type

Huh.  This is really weird:

(C:\) $ python22
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> hash(xrange)
503376880

(C:\) $ \Python21\python.exe
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
 >>> hash(xrange)
504420928

(C:\) $ \python152\python.exe
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
 >>> hash(xrange)
504409536

...?!

Maybe it's platform-specific?

Confused-ly y'rs,

-- 
Hans (hans at zephyrfalcon.org)
http://zephyrfalcon.org/





More information about the Python-list mailing list