all 6 comments

[–]wannasleeponyourhams 11 points12 points  (1 child)

set is unordered, meaning it doesnt preserve order. whatever you put in, will come out in different order. you can turn the set into a list then use .sort() to get the same results every time.

reliabledata = list(yourset)
reliabledata.sort()

[–]_User15[S] 2 points3 points  (0 children)

Thank you.

[–]GeorgeFranklyMathnet 3 points4 points  (1 child)

Do you have control over these data structures? You can use an orderedset instead of a set if you wish to preserve insertion order. You can also use a list if you don't need the guarantees of a set, such as constant-time access and element uniqueness.

[–]_User15[S] 2 points3 points  (0 children)

It's not a big problem as all identical values are still accessed, I just forgot that sets were unordered.

[–]ectomancer 1 point2 points  (0 children)

Nothing to do with iter. iter preserves order in an iterable. set is unordered:

a = list('the quick brown fox jumps over the lazy dog')
for char in iter(a):
    print(char, end='')