
28 Jan
2013
28 Jan
'13
4:24 p.m.
On Tue, Jan 29, 2013 at 2:17 AM, Ian Cordasco graffatcolmingov@gmail.com wrote:
You mean: `[n for n in range(0, 400) if n < 100 else break]`? That is definitely more obvious (in my opinion) than using the while syntax, but what does `break` mean in the context of a list comprehension?
It's easy enough in the simple case. What would happen if you added an "else break" to this:
[(x,y) for x in range(10) for y in range(2) if x<3]
Of course, this would be better written with the if between the two fors, but the clarity isn't that big a problem when it's not going to change the result. Would it be obvious that the "else break" would only halt the "for y" loop?
ChrisA