1

I have this set and when I run this program twice the order of printing is changed

S = {7, "veil", 0, -29, ("x", 11), "sun", frozenset({8, 4, 7}), 913}
print(S)

first time output:- {'veil', 0, -29, 'sun', 7, frozenset({8, 4, 7}), ('x', 11), 913}

second time output:- {0, -29, 7, frozenset({8, 4, 7}), 'veil', 913, ('x', 11), 'sun'}

I assumed that this behaviour is because only hashable objects can be added to a set and it is unordered but since a dictionary's keys are hashable and it is unordered then a dictionary should show this behaviour too, but it doesn't

Why does the order of the elements change in the set?

0 Answers0