implementation - Does anyone actually know how the order of a set is decided in Python? -



implementation - Does anyone actually know how the order of a set is decided in Python? -

this question has reply here:

'order' of unordered python sets 4 answers

there seem consistency in calling set() on string seems resolve same (non-alabetical) order, , both

class="lang-python prettyprint-override">set([1,2,3]) & set([1,2,3,4])

and jumbled cousin

class="lang-python prettyprint-override">set([2,3,1]) & set([4,3,1,2])

will result in orderly-looking set([1,2,3]).

on other hand, bit more racy, such as

class="lang-python prettyprint-override">from random import randint set([randint(0,9) x in range(3)])

will give set([9, 6, 7]) ...

... going on here?

you should consider sets unordered collections

they stored in hash table.

additionally, go on add together elements, hash shifted larger table, order may alter dramatically.

there no guarantee order same across different python versions/implementations.

python implementation cpython unordered-set

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -