sp3
>>> a = range(20)
>>>
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> for x in xrange(0,len(a),2):
... a[x],a[x+1] = a[x+1],a[x]
...
>>> a
[1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18]
>>>
остальное сам
Этот код даст ошибку при нечетной длине списка
>>> a=range(21)
>>> for x in xrange(0, len(a),2):
a[x],a[x+1]=a[x+1],a[x]
Traceback (most recent call last):
File "<pyshell#3>", line 2, in <module>
a[x],a[x+1]=a[x+1],a[x]
IndexError: list index out of range
>>>
Предлагаю несколько модифицировать
>>> a,result=range(21),[]
>>> for x in map(None,a[1::2],a[::2]):
if x[0]: result+=x
else: result.append(x[1])
>>> result
[1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]