For loop extended syntax

Kay Schluehr kay.schluehr at gmx.net
Sun Mar 20 13:47:54 EST 2005


George Sakkis wrote:

> 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)]
>

Looks very appealing, but what to do with

[x*y-z for (x=0,y,z) in (1,2,3), (4,5), (6,7,8)] ?

Should it raise an exception due to a pattern mismatch?

If not how should matching rules apply here?

[x*y-z for (x=0,y=0,z=0) in (1,2,3), (4,5), (6,7,8)]

If in doubt write a vector class that cares about the correct padding (
or more general and with geometric meaning: select the right hyperplane
) and enable to switch between different paddings. This solution is
both flexible and reusable.

Regards Kay




More information about the Python-list mailing list