Conditional iteration

Giovanni Bajo noway at ask.me
Wed Dec 13 09:58:58 EST 2006


at wrote:
> THE PROBLEM
> 
> I have a lot times the following code:
> 
> for x in [-2, -1, 0, 1, 2, 3, 4]:
>         if x > 0:
>                 ... more code...
> 
> 
> It is not the addional line containing 'if x > 0:' that bothers me, but the
> additional indentation.

for x in ...:
    if not x > 0:
       continue

    ... more code ...

-- 
Giovanni Bajo



More information about the Python-list mailing list