Answers for "swap list items in python"

0

swap list items in python

lst = ["a","b","c","d","e","f","g","h","i","j"]
n = len(lst)
for i in range(0,n-1,2):
    lst[i],lst[i+1] = lst[i+1],lst[i]
print(lst)
print(n)
Posted by: Guest on August-20-2021
-1

how to swap in list in python

list[pos1], list[pos2] = list[pos2], list[pos1]
Posted by: Guest on March-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language