13/18 when using a 2nd and new function, it uses the latest change in the list rather than the original


#1

n = [3, 5, 7, 9, 11]
def double_list(x):
_for i in range(0, len(x)):
__x[i]= x[i] * 2
_return x

print double_list(n)

def triple_list(x):
_for i in range(1, len(x)):
__x[i] = x[i] + 10
_return x

print triple_list(n)

The result is
[6, 10, 14, 18, 22]
[6, 20, 24, 28, 32]
Now why did the 2nd function use the latest change in the list rather than the original? thank you


#2

The return function alters your original array, making it something new.
So by the time triple_list sees your n array, it has been modified double_list.