2D List
Tom Pacheco
tomslists at netp.org
Mon Oct 11 15:44:50 EDT 2010
More information about the Python-list mailing list
Mon Oct 11 15:44:50 EDT 2010
- Previous message (by thread): 2D List
- Next message (by thread): 2D List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 "<pyshell#10>", line 3, in <module> > a[i].append(j) > AttributeError: 'int' object has no attribute 'append' > your creating a 1d list this creates a 2d list a=[[[]]*5 >>> [0]*5 [0, 0, 0, 0, 0] >>> [[]]*5 [[], [], [], [], []] - tom -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20101011/9c8c952b/attachment-0001.html>
- Previous message (by thread): 2D List
- Next message (by thread): 2D List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list