def troca_valor(lista, i1, i2):
a = lista[:]
tam = len(lista)
if i1 or i2 > tam:
return None
else:
a[i1] = lista[i2]
a[i2] = lista[i1]
return a
assert troca_valor([0,1,2,3],2,0) == [2,1,0,3]
assert troca_valor(["a", "e", "i", "o", "u"],1,3) == ["a", "o", "i","e", "u"]
assert troca_valor([0,1,2,3],7,3) == None
assert troca_valor([0,1,2,3],2,5) == None
I have to change the values at the list change one position per another, like in the asserts, i'm trying to do something like this code but shows a assert error. This is my first ask, i use the search but didn't fing any similar questions. Sorry for my english.