+ 2

Is there a list function that swaps two items in a list?

Example: Suppose that 'swap' is a list function: list = ['a', 'b', 'c', 'd'] list.swap(0, 3) print(list) Output: ['d', 'b', 'c', 'a']

20th Feb 2017, 2:30 AM
Erik Johanson
Erik Johanson - avatar
1 ответ
+ 1
I don't think there is any built in swap function in python but list [0], list [3] = list [3], list [0] should work
20th Feb 2017, 3:48 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar