[Tutor] Syntax for list comps
jmartiee at gmail.com
Wed Feb 3 23:52:55 EST 2016
Where can I find syntax for list comps? I am confused how/whether they are
evaluated left-right or right-left. Consider following list flattening
mx = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[value for row in mx for value in row]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
It seems like 'for' loops are evaluated from left to right (returned 'row'
is passed to right side for), but return 'value' (from second for loop) is
not on right, but left side.
That's a bit confusing syntax for me. Sorry if I am not clear in explaining
What is the reasoning behind this syntax?
More information about the Tutor