Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

List comprehension

leonardo_13 (1540 points)
6 15 22
in Programming in Python by (1.5k points)
Why if I write this:

{(x,y) for x in {1, 2, 3} for y in {'a', 'b', 'c'}}

I obtain {(2, 'c'), (3, 'c'), (1, 'c'), (2, 'a'), (3, 'a'), (2, 'b'), (1, 'a'), (3, 'b'), (1, 'b')}

and not {(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b'), (2, 'c'), (3, 'a'), (3, 'b'), (3, 'c')}?

I'm talking about page 7 of Prof Mancini's slides
234 views
closed

1 Answer

Best answer
andrea.sterbini (207940 points)
756 1270 2377
by (208k points)
selected by
Sets have no notion of ordering and produce their elements in non-deterministic order.
leonardo_13 (1540 points)
6 15 22
by (1.5k points)
Ok thank you professor.