Re: Hash of None varies per-machine

2009-04-04 Thread Peter Pearson
On 03 Apr 2009 10:57:05 -0700, Paul Rubin wrote: > ben.tay...@email.com writes: >> 1. Is it correct that if you hash two things that are not equal they >> might give you the same hash value? > > Yes, hashes are 32 bit numbers and there are far more than 2**32 > possible Python values (think of lon

Re: Hash of None varies per-machine

2009-04-04 Thread Hendrik van Rooyen
"Steven D'Aprano" wrote: >Seems to me you have misunderstood the way pickling works. Yeah right - have you ever looked at the pickle code? Good to hear it "just works" :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list

Re: Hash of None varies per-machine

2009-04-04 Thread Steven D'Aprano
On Sat, 04 Apr 2009 13:09:06 +0200, Hendrik van Rooyen wrote: >>Any object can be hashed if it has a working __hash__ method. There's no >>reason not to have None hashable -- it costs nothing and allows you to >>use None as a dict key. > > So what happens if I try to pickle the dict and keep it f

Re: Hash of None varies per-machine

2009-04-04 Thread Hendrik van Rooyen
"Steven D'Aprano" wrote: On Fri, 03 Apr 2009 10:50:08 -0700, ben.taylor wrote: >> 2. Should the hash of None vary per-machine? I can't think why you'd >> write code that would rely on the value of the hash of None, but you >> might I guess. > >The value of hash(None) appears to be the value of i

Re: Hash of None varies per-machine

2009-04-04 Thread Thomas Bellman
Steven D'Aprano wrote: > You can hash numbers no matter how big they are. > >>> hash(float('inf')) > 314159 Cute. And hash(float('-inf')) is -271828... -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "God is real, but Jesus is an integer." ! bellman @ lysa

Re: Hash of None varies per-machine

2009-04-03 Thread Steven D'Aprano
On Fri, 03 Apr 2009 10:50:08 -0700, ben.taylor wrote: > 1. Is it correct that if you hash two things that are not equal they > might give you the same hash value? Absolutely. From help(hash): hash(...) hash(object) -> integer Return a hash value for the object. Two objects with the sa

Re: Hash of None varies per-machine

2009-04-03 Thread Christian Heimes
Paul Rubin wrote: > Yes, hashes are 32 bit numbers and there are far more than 2**32 > possible Python values (think of long ints), so obviously there must > be multiple values that hash to the same slot. No, hashs are C longs. On most 64bit platforms a C long has 64bits. As far as I know only 64b

Re: Hash of None varies per-machine

2009-04-03 Thread Dave Angel
ben.tay...@email.com wrote: Found this while trying to do something unrelated and was curious... If you hash an integer (eg. hash(3)) you get the same integer out. If you hash a string you also get an integer. If you hash None you get an integer again, but the integer you get varies depending on

Re: Hash of None varies per-machine

2009-04-03 Thread Joshua Judson Rosen
Paul Rubin writes: > > ben.tay...@email.com writes: > > 1. Is it correct that if you hash two things that are not equal they > > might give you the same hash value? > > Yes, hashes are 32 bit numbers and there are far more than 2**32 > possible Python values (think o

Re: Hash of None varies per-machine

2009-04-03 Thread Paul Rubin
ben.tay...@email.com writes: > 1. Is it correct that if you hash two things that are not equal they > might give you the same hash value? Yes, hashes are 32 bit numbers and there are far more than 2**32 possible Python values (think of long ints), so obviously there must be multiple values that ha