Is there a list comprehension to do this?

Joe Sixpack joe.sixpack at whoopie.com
Wed Sep 18 22:45:58 CEST 2002


Is there a list comprehension or other 'cleaner' or 'prettier' way
to do the following:

>>> xx = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
>>> ww = []
>>> for i in range(0, len(xx), 2):
 ww.append((xx[i+1],xx[i]))

>>> ww
[(2, 1), (4, 3), (6, 5), (8, 7), (10, 9)]
>>>

Thanks in advance...





More information about the Python-list mailing list