This is my list:
l = [0, 1, 2, 3, 4, 5]
I want to swap adjacent elements, so the list should result in this:
l = [1, 0, 3, 2, 5, 4]
I know that there are lots of solutions for this and I think I found one:
def swap(l):
return l[::2], l[1::2] = l[1::2], l[::2]
Anyhow I am still getting this Error:
file.py on line 2
return l[::2], l[1::2] = l[1::2], l[::2]
^
SyntaxError: invalid syntax
Any hints or ideas how to solve this are highly appreciated. (Working on Python2)