<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
On 10/11/2010 12:24 PM, Fasihul Kabir wrote:
<blockquote cite="mid:202409.92397.qm@web114117.mail.gq1.yahoo.com"
type="cite">
<style type="text/css"><!-- DIV {margin:0px;} --></style>
<div style="font-family: times new roman,new york,times,serif;
font-size: 12pt;">
<div><span style="color: rgb(0, 0, 191);">a = [0]*5</span><br
style="color: rgb(0, 0, 191);">
<span style="color: rgb(0, 0, 191);"> for i in range(0, 4):</span><br
style="color: rgb(0, 0, 191);">
<span style="color: rgb(0, 0, 191);"> for j in range(0, i):</span><br
style="color: rgb(0, 0, 191);">
<span style="color: rgb(0, 0, 191);"> a[i].append(j)</span><br>
<br>
why the above codes show the following error. and how to
overcome it.<br>
<br>
<span style="color: rgb(255, 0, 0);">Traceback (most recent
call last):</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> File
"<pyshell#10>", line 3, in <module></span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> a[i].append(j)</span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">AttributeError: 'int'
object has no attribute 'append'</span><br>
</div>
</div>
<br>
</blockquote>
your creating a 1d list<br>
<br>
this creates a 2d list<br>
a=[[[]]*5<br>
<br>
>>> [0]*5<br>
[0, 0, 0, 0, 0]<br>
>>> [[]]*5<br>
[[], [], [], [], []]<br>
<br>
- tom<br>
<br>
<br>
</body>
</html>