I'm trying to add a value in a ordered list but the list won't change:
def insert(V, x):
if len(V)!=0:
for i in range( 0 , len(V)-1):
if (V[i]<=x)and(V[i+1]>=x):
V=V[0:i+1]+[x]+V[i+1:len(V)]
print("\nExpected: \n"+ repr(V))
return
V=V+[x]
return
i have this:
V=[1,2,3,4,5,6,7,8,9,10]
insert(V, 6)
print("\nResult: \n"+ repr(V))enter code here
and this is the result:
Expected:
[1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10]
Result:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I can solve the problem setting V as the return but I want the function to work on the list.