I do not quite understand how to read the following comprehension, even though I know what it does:
>>> matrix=[[1,2,3],[4,5,6],[7,8,9]]
>>> [x for row in matrix for x in row]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
So, how does this comprehension translate into natural language? I'm not sure because if I try to divide this expression into two parts x for row in matrix and for x in row they all become nonesense in the context of the task.
Just add a new line between fors, and make them regular for loops:
for row in matrix:
for x in row:
print x
The order is like the order of such regular loops, as the nested loops should be write outer.
[x for row in matrix for x in row for t in x]
(level 1) ---> (level 2) ---> (level 3)
---> nested loops
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With