[ x for x in xrange(10) when p(x) ]

bonono at gmail.com bonono at gmail.com
Sat Nov 12 05:11:22 EST 2005


Peter Otten wrote:
> bonono at gmail.com wrote:
>
> > However, I found something interesting which I don't quite understand :
> >
> > list((x for x in [1,2,3] if x<2 or stop())) works
> >
> > but
> >
> > a = [ x for x in [1,2,3] if x <2 or stop() ] doesn't.
>
> Here's how  Carl Banks explained it to me when Bengt came up with this
> trick.
>
> http://mail.python.org/pipermail/python-list/2005-April/274051.html
>
Thanks, but that is even more confusing for me. I thought it is the
"for" that trap the StopIteration as in :

for x in iteratables: pass

But it said it is not ?




More information about the Python-list mailing list