Conditional iteration

Paul Rubin http
Wed Dec 13 10:47:23 EST 2006


at <at at tuko.nl> writes:
> I have a lot times the following code:
> 
> for x in [-2, -1, 0, 1, 2, 3, 4]:
>         if x > 0:
>                 ... more code...

Use:

 for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
      ... more code ...



More information about the Python-list mailing list