Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Python's set absence of ordering be considered random order?

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.)

like image 742
Chuim Avatar asked May 18 '10 19:05

Chuim


People also ask

Are Python sets ordered or unordered?

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.

Is set Pop () random?

Python Set pop() The pop() method randomly removes an item from a set and returns the removed item.

Do sets care about order Python?

Characteristics of a Set in Python Sets are unordered. This means that they do not preserve the original order in which they were created.

Is Python set pop random?

Python Set pop() MethodThe pop() method removes a random item from the set. This method returns the removed item.


2 Answers

No, it is not random. It is "arbitrarily ordered", which means that you cannot depend on it being either ordered or random.

like image 62
Ignacio Vazquez-Abrams Avatar answered Sep 23 '22 03:09

Ignacio Vazquez-Abrams


In a word, no:

>>> list(set(range(10000))) == list(range(10000))
True
like image 31
Daniel Stutzbach Avatar answered Sep 22 '22 03:09

Daniel Stutzbach