Q:

Order of Elements in comprehension

I have a python method that returns the squared values in a given set.
print(str({x*x for x in {1,2,3,4,5}}))

The values are correct but not in the same are as submitted, why is this?
{16, 1, 4, 25, 9}

A:

You've created a set, rather than a list, and the order in which a set's elements are presented is arbitrary.
Compare:
>>> print([x*x for x in [1,2,3,4,5]])
[1, 4, 9, 16, 25]

