i'm having strange behavior from the for loop in python. The problem is not exactly this one but very similar to :
a = []
b = [1,2,3,4]
for i in xrange (0,10):
a.append(b)
b[3] += 1
And the result is :
a = [[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14],[1,2,3,14]]
The result i'm expecting is
a = [[1,2,3,4],[1,2,3,5],[1,2,3,6],[1,2,3,7],.....,[1,2,3,14]]
I do not know why at each iteration, b[3] is added up to 14 and then the list [1,2,3,14] is added to a. I think b[3] should only increase by 1 at each iteration
btoaat each iteration of the loop, not a copy ofb. Each reference points to the sameb, which, at the end of your loop, hasb[3] = 14.