a break for comprehensions
Terry Reedy
tjreedy at home.com
Thu Jul 26 13:27:07 EDT 2001
"Tom Jenkins" <tjenkins at nospiced.ham.devis.com> wrote in message
news:3B6031C3.6010707 at nospiced.ham.devis.com...
> Kevin Lacker wrote:
>
> > Can you do this:
> >
> > answer = []
> > for x in my_list:
> > if not is_good(x):
> > break
> > answer.append(process(x))
> >
> > with a list comprehension somehow? I'm starting to dislike
explicit for
> > loops just for the purposes of constructing another list from a
current one.
>
>
> do you mean like this?
[filter the list]
No, 'break' stops the for loop. Good things after non-good x do not
get processed and appended.
Terry J. Reedy
More information about the Python-list
mailing list