I m newest in Python.
i dont understand why in result of the code {9, 4} first number is 9 but not 4 ? iteration begin from the first set ?
{x*y for x in {1,2,3} for y in {2,3,4} if x == y}
{9, 4}
I m newest in Python.
i dont understand why in result of the code {9, 4} first number is 9 but not 4 ? iteration begin from the first set ?
{x*y for x in {1,2,3} for y in {2,3,4} if x == y}
{9, 4}
The result is a set so ordering does not matter. If you ran the same thing using lists (replace {} with []) then you would get [4, 9].
Sets are unordered. The order of elements in a set is defined by a hash function, not the order of insertion.