In In for in for in Out In for in for in Out

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
In [1]: a = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
In [2]: [(x, y) for x in a for y in x]
Out[2]:
[([1, 1, 1], 1),
([1, 1, 1], 1),
([1, 1, 1], 1),
([2, 2, 2], 2),
([2, 2, 2], 2),
([2, 2, 2], 2),
([3, 3, 3], 3),
([3, 3, 3], 3),
([3, 3, 3], 3)]
In [3]: [(x, y) for y in x for x in a]
Out[3]:
[([1, 1, 1], 3),
([2, 2, 2], 3),
([3, 3, 3], 3),
([1, 1, 1], 3),
([2, 2, 2], 3),
([3, 3, 3], 3),
([1, 1, 1], 3),
([2, 2, 2], 3),
([3, 3, 3], 3)]