I'd like to know if the absence of element ordering of the Python's built-in set
structure is "random enough". For instance, taking the iterator of a set, can it be considered a shuffled view of its elements?
(If it matters, I'm running Python 2.6.5 on a Windows host.)
Sets are unordered. Set elements are unique. Duplicate elements are not allowed. A set itself may be modified, but the elements contained in the set must be of an immutable type.
Python Set pop() The pop() method randomly removes an item from a set and returns the removed item.
Characteristics of a Set in Python Sets are unordered. This means that they do not preserve the original order in which they were created.
Python Set pop() MethodThe pop() method removes a random item from the set. This method returns the removed item.
No, it is not random. It is "arbitrarily ordered", which means that you cannot depend on it being either ordered or random.
In a word, no:
>>> list(set(range(10000))) == list(range(10000))
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With