You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary
The set.pop() method almost always returns elements in the same order — typically numbers in ascending order, followed by strings.
In the rare cases where the order changes, it's always the position of the string(s) that varies. The numbers are consistently returned in ascending order, regardless of how the set is defined.
I've run this test over 100 times and have never seen the numeric order change. Is this expected behavior, or is it an implementation detail specific to CPython?
Description
The set.pop() method seems to return elements in a consistent and predictable order under CPython 3.13.
Based on my testing:
Numbers are always returned in ascending order, no matter the order in which they were added to the set.
Strings (and possibly other types) are the only elements whose position may vary between runs.
This behavior is reproducible and highly consistent for numbers.
Observations
The relative position of numbers never changes: 1.4, 2, 3, 4, 5 always come in that order.
The string "nombre" is the only element whose position varies across runs.
I've tested this more than 100 times using CPython 3.13, and the numeric order is always preserved.
Question
Is this deterministic order for numbers an implementation detail, or is it guaranteed behavior in CPython 3.13? Should set.pop() be expected to behave this way?
CPython versions tested on:
3.13
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered:
A bug is a discrepancy between behavior and doc. There is none here. 'arbitrary' means arbitrary -- whatever is chosen however. Specifics are an implementation detail. Please asked questions like this on https://discuss.python.org/c/help/7.
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
Summary
The set.pop() method almost always returns elements in the same order — typically numbers in ascending order, followed by strings.
In the rare cases where the order changes, it's always the position of the string(s) that varies. The numbers are consistently returned in ascending order, regardless of how the set is defined.
I've run this test over 100 times and have never seen the numeric order change. Is this expected behavior, or is it an implementation detail specific to CPython?
Description
The set.pop() method seems to return elements in a consistent and predictable order under CPython 3.13.
Based on my testing:
Numbers are always returned in ascending order, no matter the order in which they were added to the set.
Strings (and possibly other types) are the only elements whose position may vary between runs.
This behavior is reproducible and highly consistent for numbers.
Sample outputs:
Most commonly:
1.4
2
3
4
5
nombre
Sometimes:
1.4
2
3
4
nombre
5
Or:
1.4
2
3
4
nombre
5
Or:
1.4
nombre
2
3
4
5
Observations
The relative position of numbers never changes: 1.4, 2, 3, 4, 5 always come in that order.
The string "nombre" is the only element whose position varies across runs.
I've tested this more than 100 times using CPython 3.13, and the numeric order is always preserved.
Question
Is this deterministic order for numbers an implementation detail, or is it guaranteed behavior in CPython 3.13? Should set.pop() be expected to behave this way?
CPython versions tested on:
3.13
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: