Fw: [Python-Dev] Use for enumerate()
Sat, 27 Apr 2002 13:20:59 -0400
> > > > Challenge 3: do it faster and with less code.
> > it should work even if the file is too large
> > to fit in memory (as long as each individual line fits in memory).
def getline(filename, lineno):
if lineno < 1:
f = open(filename)
g = f.readline
return (reduce(lambda x,y: g(), range(lineno), ''), f.close())
This incorporates a couple of ideas inspired by Tim's post.