Re: [Tutor] parsing an array

2007-11-15 Thread Kent Johnson
sith . wrote: > a = [[1,1],[3,1.5],[5,0]] > for i in range(len(a)) : This should use range(1, len(a)). You don't want i to take on the value 0. > if a[i][1] > a[i-1][1] : When i==0 this compares a[0] to a[-1] which is the *last* element of the list; a[0][1] > a[-1][1] so it prints 'greater

Re: [Tutor] parsing an array

2007-11-15 Thread Aditya Lal
On Nov 15, 2007 12:37 PM, sith . <[EMAIL PROTECTED]> wrote: > a = [[1,2],[3,1.5],[5,6]] > for i in a: > print i > if i[1]>i[0]: > print "second index is larger" > else: > print "second index is smaller" > [1, 2] > second index is larger > [3, 1.5] > second index is smal

Re: [Tutor] parsing an array

2007-11-13 Thread Aditya Lal
On Nov 13, 2007 7:06 PM, bob gailer <[EMAIL PROTECTED]> wrote: > Aditya Lal wrote: > > [snip] > > > for i in a[:] will make i point to the elements of the list > To be more precise: > a[:] is a copy of the list > the for statement assigns each list element in turn to i. Assign is not > exactly the

Re: [Tutor] parsing an array

2007-11-13 Thread bob gailer
Aditya Lal wrote: > [snip] > for i in a[:] will make i point to the elements of the list To be more precise: a[:] is a copy of the list the for statement assigns each list element in turn to i. Assign is not exactly the same as point. ___ Tutor maillis

Re: [Tutor] parsing an array

2007-11-12 Thread Aditya Lal
On Nov 13, 2007 8:29 AM, sith . <[EMAIL PROTECTED]> wrote: > 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

Re: [Tutor] parsing an array

2007-11-09 Thread O.R.Senthil Kumaran
* sith . <[EMAIL PROTECTED]> [2007-11-09 17:53:53]: > newfile = open('y.txt') > >>> for line in newfile: > ... print line.rstrip() > > 3 5 7 > 11 8 10 This example is different from a array handling one. This is a file handle with with reading the contents of the file through a loop.