-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Closed as not planned
Closed as not planned
Copy link
Description
Bug report
Bug description:
The doc of sets says A set is an unordered collection as shown below:
A set is an unordered collection with ....
So for str
elements, set() and frozenset() return the sets with unordered elements as the doc says as shown below:
print(set({'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}))
# {'A', 'I', 'B', 'E', 'H', 'D', 'G', 'F', 'J', 'C'}
print(frozenset({'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}))
# frozenset({'A', 'I', 'B', 'E', 'H', 'D', 'G', 'F', 'J', 'C'})
But for int
, float
, complex
and bool
elements, set()
and frozenset()
return the sets with ordered elements against the doc says as shown below:
print(set({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}))
print(set({9, 8, 7, 6, 5, 4, 3, 2, 1, 0}))
# {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
print(set({0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}))
print(set({9., 8., 7., 6., 5., 4., 3., 2., 1., 0.}))
# {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}
print(set({0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j, 5.+0.j, 6.+0.j, 7.+0.j, 8.+0.j, 9.+0.j}))
print(set({9.+0.j, 8.+0.j, 7.+0.j, 6.+0.j, 5.+0.j, 4.+0.j, 3.+0.j, 2.+0.j, 1.+0.j, 0.+0.j}))
# {0j, (1+0j), (2+0j), (3+0j), (4+0j), (5+0j), (6+0j), (7+0j), (8+0j), (9+0j)}
print(set({True, False}))
print(set({False, True}))
# {False, True}
print(frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}))
print(frozenset({9, 8, 7, 6, 5, 4, 3, 2, 1, 0}))
# frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
print(frozenset({0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}))
print(frozenset({9., 8., 7., 6., 5., 4., 3., 2., 1., 0.}))
# frozenset({0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0})
print(frozenset({0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j, 5.+0.j, 6.+0.j, 7.+0.j, 8.+0.j, 9.+0.j}))
print(frozenset({9.+0.j, 8.+0.j, 7.+0.j, 6.+0.j, 5.+0.j, 4.+0.j, 3.+0.j, 2.+0.j, 1.+0.j, 0.+0.j}))
# frozenset({0j, (1+0j), (2+0j), (3+0j), (4+0j), (5+0j), (6+0j), (7+0j), (8+0j), (9+0j)})
print(frozenset({True, False}))
print(frozenset({False, True}))
# frozenset({False, True})
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Metadata
Metadata
Assignees
Labels
No labels