an enumerate question

Terry Hancock hancock at
Wed Mar 21 11:03:27 CET 2007

eight02645999 at wrote:
> say i want to enumerate lines of a file
> eg
> for n,l in enumerate(open("file")):
>      # print  next line ie

I think you'd find it much easier to move your frame of reference one
line forward and think in terms of remembering the previous line, e.g.:

for n,curr in enumerate(open("file")):
    if n>1:
        print n,curr
        print m,prev
    m,prev = n,curr

Of course, if the file isn't so big, then you could use readlines as you


Terry Hancock (hancock at
Anansi Spaceworks

More information about the Python-list mailing list