for loop possible enhancement

Dan Schmidt dfan at
Fri Sep 22 20:54:28 CEST 2000

bob van der Poel <bvdpoel at> writes:

| Playing with some for/next loops I find that having something like
| 	for a,b in [[1,2],[3,4],[4,5]]:
| 		...
| works nicely. However, what would be more useful at times is the
| possiblity to:
| 	for a,b in [[1,2,3,4], [a,b,c,d]]:
| which, intutively(?) would set a to the value 1 and b to 'a', etc.

You can do this now with the slightly unwieldy map (None,...) idiom:

  for a, b in map (None, [1,2,3,4], [5,6,7,8]):

or, in Python 2.0, which is currently in beta, so if you don't want be
tantalized by features that are available only in beta releases stop
reading now, you can use the 'zip' builtin function:

  for a, b in zip ([1,2,3,4], [5,6,7,8]):

                 Dan Schmidt |
Honest Bob CD now available! |

More information about the Python-list mailing list