[Python-3000] Parallel iteration syntax

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Mar 29 04:52:15 CEST 2006


Michael Chermside wrote:

> There's one big problem I see with this. Parallel iteration
> is underspecified... there are several reasonable choices
> for what to do if the iterables are of differing length.

I have trouble seeing that as a *big* problem.
I'd go for raising an exception (when in doubt...)

Most of the time it's probably a bug if the sequences
are of diffent lengths. If not, the user can catch
the exception and take appropriate action. Especially
if the exception includes info about which sequence
was shorter.

> Today, we support these with different idioms:
 >
>    (1)
>    result = map(some_func, seq_x, seq_y)
> 
>    (2)
>    for x, y in zip(seq_x, seq_y):
>       some_func(x, y)

It's really only an accident that these correspond
to different handlings of unequal length sequences,
though, especially considering that we're trying to
make the need for map() go away with things like
zip() and LCs. If it were a deliberate feature, we'd
have different versions of zip() corresponding to
the different behaviours.

Greg


More information about the Python-3000 mailing list