[Python-ideas] while conditional in list comprehension ?? (original) (raw)
Chris Angelico rosuav at gmail.com
Mon Jan 28 16:24:56 CET 2013
- Previous message: [Python-ideas] while conditional in list comprehension ??
- Next message: [Python-ideas] while conditional in list comprehension ??
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 29, 2013 at 2:17 AM, Ian Cordasco <graffatcolmingov at 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 doesbreakmean 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
- Previous message: [Python-ideas] while conditional in list comprehension ??
- Next message: [Python-ideas] while conditional in list comprehension ??
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]