[Python-ideas] Variations on a loop

Bruce Frederiksen dangyogi at gmail.com
Fri Aug 29 14:49:32 CEST 2008


Bruce Leban wrote:
>
> For example:
>
>     result = ""
>     for x in items:
>         result += str(x)
>     interstitially:
>         result += ", "
>     contrariwise:
>         result = "no data"
We already have statements that only apply within loops (break and 
continue), how about some expressions that only apply in for loops: 
'last' and 'empty':

for x in items:
    result += str(x)
    if not last:
        result += ', '
else:
    if empty:
        result = "no data"

-bruce (not to be confused with Bruce :-)



More information about the Python-ideas mailing list