On Sep 6, 9:30 am, John Machin <[EMAIL PROTECTED]> wrote: > On Sep 6, 7:49 am, [EMAIL PROTECTED] wrote: > > > John Machin: > > > > Consider this:>>> hash(123) == hash(123.0) == hash(123L) > > > True > > > Right... Can you explain me why Python designers have chosen to build > > a hash() like that? > > I can't channel them; my rationalisation is this: > > Following the Law of Least Astonishment,>> 123 == 123.0 == 123L > > True > > Consequently if x == y, then adict[x] and adict[y] should give the > same result. >
Another reason for not folding in the type of the object is this: >>> type([]) <type 'list'> >>> hash(type([])) 505252536 >>> id(type([])) 505252536 IOW hash(T) == id(T) where T is a type. id(obj) is just a memory address which can vary between executions of the same Python binary on the same machine ... not very reproducible. There is no guarantee in the docs for hash about under what circumstances hash(x) != hash(x) of course; I'm just relying on the least astonishment law again :-) And, again, we don't know what the OP's full requirements are ... -- http://mail.python.org/mailman/listinfo/python-list