<br><br><div class="gmail_quote">On Tue, Nov 3, 2009 at 4:20 PM, Robert Berman <span dir="ltr">&lt;<a href="mailto:bermanrl@cfl.rr.com">bermanrl@cfl.rr.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




  
  

<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td>
<br>
</td>
</tr>
</tbody></table>
In [69]: l1=[(0,0)] * 4<br>
<br>
In [70]: l1<br>
Out[70]: [(0, 0), (0, 0), (0, 0), (0, 0)]<br>
<br>
In [71]: l1[2][0]<br>
Out[71]: 0<br>
<br>
In [72]: l1[2][0] = 3<br>
---------------------------------------------------------------------------<br>
TypeError                                 Traceback (most recent call last)<br>
<br>
/home/bermanrl/&lt;ipython console&gt; in &lt;module&gt;()<br>
<br>
TypeError: &#39;tuple&#39; object does not support item assignment<br>
<br>
First question, is the error referring to the assignment (3) or the index [2][0]. I think it is the index but if that is the case why does l1[2][0] produce the value assigned to that location and not the same error message.<br>


<br>
Second question, I do know that l1[2] = 3,1 will work. Does this mean I must know the value of both items in l1[2] before I change either value. I guess the correct question is how do I change or set the value of l1[0][1] when I specifically mean the second item of an element of a 2D array?<br>


<br>
I have read numerous explanations of this problem thanks to Google; but no real explanation of setting of one element of the pair without setting the second element of the pair as well.<br>
<br>
For whatever glimmers of clarity anyone can offer. I thank you.<br></div></blockquote><div><br>Tuples are immutable types. Thus it is not possible to change one of the values of a tuple (or even of changing both of them). The only thing you can do, is create a new tuple, and put that in the same place in the list. In your example, when you do l1[2][0] = 3, you try to change the tuple l1[2], which is impossible.<br>

<br>To do what you want to do, you have to create a new array with the same second but different first value, and put that array in l1[2], that is:<br><br>l1[2] = (3, l1[2,1])<br><br><br> </div></div><br>-- <br>André Engels, <a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a><br>

<br>