Consider the following example:
s = 'abc'
[(c1, c2) for j, c2 in enumerate(s) for i, c1 in enumerate(s)]
Output:
[('a', 'a'),
('b', 'a'),
('c', 'a'),
('a', 'b'),
('b', 'b'),
('c', 'b'),
('a', 'c'),
('b', 'c'),
('c', 'c')]
I would expected the same output if enumerate is called outside the list comprehension and the iterators are assigned to variables:
it1, it2 = enumerate(s), enumerate(s)
[(c1, c2) for j, c2 in it1 for i, c1 in it2]
But I get:
[('a', 'a'), ('b', 'a'), ('c', 'a')]
What is going on? I use Python 3.6.9.