[Python-3000] Parallel iteration syntax

Georg Brandl g.brandl at gmx.net
Tue Mar 28 20:13:31 CEST 2006


Guido van Rossum wrote:

>> Slightly too late for consideration, I did come up with
>> what I believe is a backwards-compatible syntax extension
>> to support this:
>>
>>    for (x in iter1, y in iter2):
>>      ...

[...]
> Based on the feedback so far I think not. There's also the issue that
> 
>   for (x in A, y in B):
> 
> could just as well be meant as a shortcut for
> 
>   for x in A:
>     for y in B:
> 
> The proposed syntax doesn't quite jive with my guts, and the issue of
> "what to do if they are of unequal length" is a good one, which is
> better solved by being explicit and using zip (== izip).
> 
> Finally (maybe this is why it doesn't jive :-) it seems to me that
> separating the variables is *worse* than
> 
>   for x, y in zip(A, B):
> 
> because the latter emphasizes that you get a new x and a new y at the same time.

I agree. A related issue is, when map() is gone, could zip() grow a keyword
argument, say, 'extend' so that

map(None, A, B)

translates to

zip(A, B, extend=None)?

zip(A, B, extend=0) would fill with 0 etc.

Georg



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: OpenPGP digital signature
Url : http://mail.python.org/pipermail/python-3000/attachments/20060328/1cc37db8/attachment.pgp 


More information about the Python-3000 mailing list