Conditional iteration

at at at tuko.nl
Wed Dec 13 13:25:11 EST 2006


You proposal, seems nice to me but it doesn't work with Python 2.4.3, should
it work with 2.5?

Again I am just wondering if the approach for 

        [x for c x in some_list if some_condition]

and
        x = a if b else c

could be generalized for normal straight forward iterations:

for x in some_list if some_condition:

        --- etc...

I am not looking for a work around but more interest if other people might
judge this syntax would come in handy?

Interested in any feedback!

Kind regards,

@






Paul Rubin wrote:

> 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