[Tutor] parsing an array

sith . sith618 at yahoo.com
Tue Nov 13 03:59:24 CET 2007


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

       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071112/4d25bea4/attachment.htm 


More information about the Tutor mailing list