Re: 2D List

2010-10-12 Thread Ian Kelly
On Mon, Oct 11, 2010 at 1:44 PM, Tom Pacheco wrote: > your creating a 1d list > > this creates a 2d list > a=[[[]]*5 > > > >>> [0]*5 > [0, 0, 0, 0, 0] > >>> [[]]*5 > [[], [], [], [], []] > Don't do this. This actually just creates a list containing the same empty list 5 times: >>> a = [[]] * 5

Re: 2D List

2010-10-11 Thread Tom Pacheco
On 10/11/2010 12:24 PM, Fasihul Kabir wrote: a = [0]*5 for i in range(0, 4): for j in range(0, i): a[i].append(j) why the above codes show the following error. and how to overcome it. Traceback (most recent call last): File "", line 3, in a[i].append(j) AttributeError: 'int

Re: 2D List

2010-10-11 Thread Gary Herron
On 10/11/2010 09:24 AM, Fasihul Kabir wrote: a = [0]*5 for i in range(0, 4): for j in range(0, i): a[i].append(j) why the above codes show the following error. and how to overcome it. Traceback (most recent call last): File "", line 3, in a[i].append(j) AttributeError: 'int'

Re: 2D List

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 9:24 AM, Fasihul Kabir wrote: > a = [0]*5 >  for i in range(0, 4): >     for j in range(0, i): >         a[i].append(j) > > why the above codes show the following error. and how to overcome it. > > Traceback (most recent call last): >   File "", line 3, in >     a[i].appen

Re: 2D List

2010-10-11 Thread Nitin Pawar
the declaration is wrong if you want to create a two dimensional array try to use functions like arange and reshape On Mon, Oct 11, 2010 at 9:54 PM, Fasihul Kabir wrote: > a = [0]*5 > for i in range(0, 4): > for j in range(0, i): > a[i].append(j) > > why the above codes show the fo