for <var> in <sequence> if <condition>
Fredrik Lundh
effbot at telia.com
Thu Oct 5 11:16:38 EDT 2000
Dave Brueck wrote:
> So is there any good reason why we can't enhance the for-loop to handle the
> if-condition for me? ie-
>
> for line in lines if line.strip.startswith('y'):
> doStuff(line)
iirc, SETL (from which the list comprehension idea was
taken) has a similar construct.
but frankly, I doubt it's worth the effort -- you're only
saving a colon and a newline:
for line in lines:
if line.strip.startswith('y'):
doStuff(line)
</F>
More information about the Python-list
mailing list