A list comprehension to do this?...

joe sixpack joe.sixpack at quartercase.com
Wed Sep 18 16:41:25 EDT 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