parallel for loops

Ryan Lowe ryanlowe0 at msn.com
Tue Apr 27 18:09:00 EDT 2004


maybe its just me, but the behavior of parallel lists in for loops seems
backwards. why doesnt it mirror parallel assignment? i think tuple-unpacking
should take precedence, but instead iteration happens along the first
dimension and unpacking comes second, forcing the use of zip.

>>> a, b = [1,2,3], [4,5,6]     # a = [1,2,3], b = [4,5,6]
>>> for a, b in zip([1,2,3], [4,5,6]): print a, b

instead of:
>>> for a, b in [1,2,3], [4,5,6]: print a, b     # illegal

im sure there is a good reason why the former was chosen, and i know its way
too late to switch, but i cant think of many examples of when you would use
parallel iteration *without* zip. not even dictionaries since you have to
use .items() anyway (another thing that should be default in my mind). of
course, using zip is no big deal but im just curious, from a design
perspective why the choice was made.





More information about the Python-list mailing list