hashval and Numpy

Uwe Schmitt uwe at rocksport.de
Wed Oct 17 13:36:00 EDT 2001


Michael Hudson <mwh at python.net> wrote:

|>>> a = Numeric.array([1,2])
|>>> hash(a)
| 56
|>>> d = {a:1} # a will be in the 56%8-th slot (in 2.2, anyway)
|>>> a[0] = 2
|>>> hash(a)
| 57
|>>> d[a] # looks in 57%8-th slot - which is empty
| KeyError
|>>> b = Numeric.array([1,2])
|>>> hash(b)
| 56
|>>> d[b] # looks in 56%8-th slot - but what's there is not __eq__ to b!
| KeyError

| Moral: don't use mutable objects as dictionary keys.

allright,  i understand. thanks. yours, uwe.

-- 
Uwe.Schmitt at num.uni-sb.de      Universität des Saarlandes
phone: +49 (0)681/302-2468     Geb. 36.1, Zi. 4.17, PF 151150
                               D-66041  Saarbrücken
http://www.rocksport.de        http://www.rocksport.de/first_ride.mp3




More information about the Python-list mailing list