<br><div class="gmail_quote">On Nov 13, 2007 8:29 AM, sith . &lt;<a href="mailto:sith618@yahoo.com">sith618@yahoo.com</a>&gt; 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>a = [[0,1,2,3,4,5],[1,2,3,4,5,6]]</div>  <div>You cannot modify the same array when you are looping through it. You have to loop through the copy of the contents :- a[:].</div>  <div>&nbsp;</div>  <div># Untested code</div>
  <div>for i in a[:]: # You are looping through the copy of contents</div>  <div>&nbsp;</div>  <div># I&#39;m new I&#39;m going to try and explain my understanding of this code; pls correct if wrong<br># i[0] is [0,1,2,3,4,5] and i[1] is the other
<br># the loop first goes to the list on the left then goes to the list on the right</div>  <div><br>&nbsp;&nbsp; for j in i:</div>  <div><br>#each element in the sublist is now evaluated<br># first 0 in i[0] then 1 in i[1] then back to 1 in i[0] and then to 2 in i[1]--------- is this right? 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # implement your logic with j<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if j &lt; i[0]: # or any dynamic conditional check.</div>  <div><br>the first time this loops,<br>0 in the first list
 or i[0] is evaulated against itself<br>what is the next j value for the next loop?<br>&nbsp;&nbsp; a[i][j] = j &lt;--------- don&#39;t understand this bit</div>  <div>&nbsp;</div>  <div>&nbsp;</div>  <div><br>Does this help you?</div>  <div>
&nbsp;</div>  <div>I&#39;ve looked on the net as well as my book (python dummies), but can&#39;t find an explantion for nested for loops in&nbsp;nested lists.&nbsp; Would it be possible to explain?&nbsp; Thank you.</div><div class="WgoR0d"><p>
 



      </p><hr size="1"></div><br></blockquote></div><br>Not sure but it looks like you want to iterate over an array of array (using C syntax).<br>
<br>
for i in a[:] will make i point to the elements of the list and not
its index. For getting the index you need to use enumerate or just range(len(a)) as in :<br>
<br>
for i in range(len(a)) :<br>
&nbsp;&nbsp;&nbsp; # now you can access element as a[i]<br>
&nbsp;&nbsp;&nbsp; for j in range(len(a[i])) :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # now you can access the inner array element as a[i][j]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[i][j] *= 2<br>
<br>You can use this to modify the array content as well. But do exercise caution in case of length change.<br><br>Or have I completely misunderstood your question ?<br><br>
--<br>
Aditya<br><br>