[Tutor] parsing an array

sith . sith618 at yahoo.com
Thu Nov 15 15:36:59 CET 2007


a = [[1,1],[3,1.5],[5,0]]
  for i in range(len(a)) :
    if a[i][1] > a[i-1][1] :
        print 'greater !!'
    else:
        print "smaller"
  greater !!
  greater !!
  smaller
  
Thanks for taking the time to help me Aditya.  I tried the code but have encountered a problem.  In this new list,
[1,    1]
[3,    1.5]
[5,    0]
  only the second and third "greater" and "smaller" output are correct as 1.5 is larger than 1 and 0 is smaller than 1.5.  What is i[1] greater than?  
  I also tried using + for next item instread, but that produced an error.  Why?
    if a[i][1] > a[i+1][1] 

       
---------------------------------
Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071115/ec206ba6/attachment.htm 


More information about the Tutor mailing list