Monday, May 12, 2008

Python tuple unpacking within a loop

Python tuple unpacking gets rid of tuple indices and temporary variables.

>>> a = range(11, 15)
>>> b = zip(range(21, 25), range(31, 35))
>>> for x, (y, z) in zip(a, b):
... print x, y, z
...
11 21 31
12 22 32
13 23 33
14 24 34

No comments: