Python: Are `hash` values for built-in numeric types, strings standardised? -


i came question while pondering ordering of set, frozenset , dict. python doesn't guarantee ordering, , ordering coupled hash value @ level. hash value value of numeric or string built-in type standardized? in other words,

hash((a,b,c,d,e,f,g)) 

have determined value, if a, b, c, d, e, f, g numeric values or str?

the hash values strings , integers absolutely not standardized. change new implementation of python, including between 2.6.1 , 2.6.2, or between mac , pc implementation of same version, etc.

more importantly, though, stable hash values doesn't imply repeatable iteration order. cannot depend on ordering of values in set, ever. within 1 process, 2 sets can equal , not return values in same order. can happen if 1 set has had many additions , deletions, other has not:

>>> = set() >>> in range(1000000): a.add(str(i)) ... >>> in range(6, 1000000): a.remove(str(i)) ... >>> b = set() >>> in range(6): b.add(str(i)) ... >>> == b true >>> list(a) ['1', '5', '2', '0', '3', '4'] >>> list(b) ['1', '0', '3', '2', '5', '4'] 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -