How is the element selected when popping one from a set?

Viewed 56

Many websites claim that the pop() method removes a random element from the set.

I'm confused because popping an element seems to be a deterministic process:

>>> {1,2,3,4,5}.pop()
1
>>> {1,2,3,4,5}.pop()
1
>>> {1,2,3,4,5}.pop()
1

This behaviour seems to be independent of the set contents

>>> {'a', type(2), (1)}.pop()
<class 'int'>
>>> {'a', type(2), (1)}.pop()
<class 'int'>
>>> {'a', type(2), (1)}.pop()
<class 'int'>

Why is this the case? How does pop() internally work? Is it incorrect to say that the pop() method is random?

0 Answers
Related