Re: [Tutor] python 2D list

2008-05-23 Thread Kent Johnson
On Fri, May 23, 2008 at 5:22 PM, Yuanxin Xi <[EMAIL PROTECTED]> wrote: > I'm a Python newbie and still exploring, just surprised to see this 2D list > assignment while debugging. http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list Kent __

Re: [Tutor] python 2D list

2008-05-23 Thread Alan Gauld
"Yuanxin Xi" <[EMAIL PROTECTED]> wrote I'm a Python newbie and still exploring, just surprised to see this 2D list assignment while debugging. >>> a = [[0] *3] *4 This creates a list with 3 zeros then creates a second list with 4 references to the first list. Remember that in Python all var

[Tutor] python 2D list

2008-05-23 Thread Yuanxin Xi
I'm a Python newbie and still exploring, just surprised to see this 2D list assignment while debugging. >>> a = [[0] *3] *4 >>> a [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> a[1][2] = 1 >>> a [[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]] why is that a[0][2] a[1][2] a[2][2] a[3][2] are all a