This is not really a question about an error. Rather, a clarification on how things work.
I am putting an element(0 for example) inside an array which is also inside an array. Doing it iteratively, the code looks like this:
arr = [[0 for x in range(2)] for x in range(2)]
Recursively,
def zero(array,n,i):
if i >= n:
return array
else:
array[i].append(0)
return zero(array,n,i+1)
arr = [[]] * 2
print zero(arr,2,0)
They would both have an output like this: [[0,0],[0,0]]
I did not get the process that the recursion underwent(I just accidentally made that code through trial and error.).
What I did not get was since I am appending zero in the first array(with index zero) inside the bigger array, shouldn't '0' be appended only in the first array and not on the second array? But that is not the case, '0' was appended to both array. And when it returns the function, instead of appending '0' to the second array, it was appended to both array again.
I tried to trace it but I really don't understand how it happened. Thank you for the response.