For loop extended syntax

George Sakkis gsakkis at rutgers.edu
Sun Mar 20 14:47:59 EST 2005


"Matteo Dell'Amico" <della at toglimi.linux.it> wrote:

> George Sakkis wrote:
> > I'm sure there must have been a past thread about this topic but I don't know how to find it:
How
> > about extending the "for <X> in" syntax so that X can include default arguments ? This would be
very
> > useful for list/generator comprehensions, for example being able to write something like:
> >
> > [x*y-z for (x,y,z=0) in (1,2,3), (4,5), (6,7,8)]
> >
> > instead of the less elegant explicit loop version that has to check for the length of each
sequence.
> > What do you think ?
>
> How did you get the data in that format in the first place? It looks a
> bit strange to me. Wouldn't it be easier to fill in default values when
> you gather data as opposed to when you use it?

Not always. Say for example that you're doing some 2D geometry stuff, and later you have to extend
it to 3D. In this case you may have to deal with both 2D and 3D objects, and map the former to the
latter when necessary.

George





More information about the Python-list mailing list