x1 = {'foo', 'bar', 'baz'}
x2 = {'baz', 'qux', 'quux'}
a=((x1.union(x2)))
b=(x1 | x2)
print(a) #{'qux', 'bar', 'quux', 'baz', 'foo'}
print(b) #{'qux', 'bar', 'quux', 'baz', 'foo'}
# a and b are always printed in a same order
print(a is b) #false
the order of a
and b
on each execution will change, but their order are always same when they printed.
as set is unordered I expected the order of a
and b
on print, should be different.
i have read these 2 associated links, but couldn't find a answer:
Why does a set display in same order if sets are unordered?
Why is the order in dictionaries and sets arbitrary?