It would help to know what “codes do not work” means. Do you get an error message, or does the function f() not produce the result you want.
It may be that you do not have much experience with the Python programming language. There is extensive documentation available at <
https://python.org>.
In case your copy of the code you are writing was exactly what you used, the problem may be that you are not following the indentation rules that Python uses. This code, which is the same as yours, except for indentation, works for me:
def f(i, v1):
v=[]
for j in v1:
v.append(j)
print(v)
v[i+1]=v1[i]
v[i]=v1[i+1]
return v
HTH
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
Deal with it.
--------