During my work with python I've met one blocking problem. I have SomeFunction which should do some simple calculation (and also sorting it - I remove that piece of code for keep it more clear) over given vector of integers and return new one. Main problem is, that result of each inside loop must become an input for next one but variable k and X seems to have the same address in memory.
Function looks like this:
def SomeFunction(k, N):
X = range(N);
for i in range(N):
for j in range(3):
X[i] = k[i]*2;
print "X:";
print X;
print "k -> :";
print k
k = X;
print "============================";
return k;
and it produce output:
X: [0, 1, 2, 3, 4, 5, 6, 7] k -> : [0, 1, 2, 3, 4, 5, 6, 7] ============================ X: [0, 8, 2, 3, 4, 5, 6, 7] k -> : [0, 8, 2, 3, 4, 5, 6, 7] ============================
Output for first loop is ok, because first element is 0, but then for the rest of the loops you can see the problem. X should have new value while k should be the same. Does anyone have any idea how solve this problem?