Why is the set {1, 3, 5, 7} always ordered in python 3.9?

Viewed 48

I have searched all over for an answer to this, however, every site tells me what I already know - that sets are an unordered collection of values. I don't dispute this in any way.

What makes no sense to me and what I can't get my head around, is when creating a set of the integers 1, 3, 5, and 7 in Python3.9 they are always retrieved/printed in order. Other sets of ints are stored unordered as expected (as far as I've checked). I suppose what I'm asking is, is this a quirk of Python, a misnomer of set theory, or just an incredibly marginal coincidence?

I came across this quirk in code different to that of below, however, I had to check all possible ways of creating the set and that's what I've shared:

listOfSets =    [
                {1, 3, 5, 7},
                {1, 3, 7, 5},
                {1, 5, 3, 7},
                {1, 5, 7, 3},
                {1, 7, 5, 3},
                {1, 7, 3, 5},
                {7, 3, 5, 1},
                {7, 3, 1, 5},
                {7, 5, 3, 1},
                {7, 5, 1, 3},
                {7, 1, 5, 3},
                {7, 1, 3, 5},
                {5, 3, 1, 7},
                {5, 3, 7, 1},
                {5, 1, 3, 7},
                {5, 1, 7, 3},
                {5, 7, 1, 3},
                {5, 7, 3, 1},
                {3, 1, 5, 7},
                {3, 1, 7, 5},
                {3, 5, 1, 7},
                {3, 5, 7, 1},
                {3, 7, 5, 1},
                {3, 7, 1, 5},
                ]

for x in listOfSets:
    print(x)

Output:

{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
{1, 3, 5, 7}
0 Answers
Related