Re: [Tutor] Generate array, different results

2012-09-21 Thread Prasad, Ramit
Pavel Andreev wrote: > Hello all > A question from very beginner. > I generate a simple example array and then print its elements on the screen. > > f=[[0]*3]*3 # array initialization Your problem is above. Let us rewrite the above line as a = [0]*3 f = [a]*3 Variable `a` i

Re: [Tutor] Generate array, different results

2012-09-21 Thread eryksun
On Fri, Sep 21, 2012 at 2:47 PM, Pavel Andreev wrote: > > f=[[0]*3]*3 # array initialization The above isn't giving you what you want. All 3 sublists are the same object: >>> f = [[0]*3]*3 >>> map(id, f) [149391980, 149391980, 149391980] Do this instead: >

[Tutor] Generate array, different results

2012-09-21 Thread Pavel Andreev
Hello all A question from very beginner. I generate a simple example array and then print its elements on the screen. f=[[0]*3]*3 # array initialization for i in range(3): for j in range(3): f[i][j]=str(i)+str(j)# make simple example array print f[i][j]