[Python-Dev] Use for enumerate()

David Ascher DavidA@ActiveState.com
Fri, 26 Apr 2002 17:06:28 -0700

def getline(filename, lineno):
    if lineno >= 1:
         for i, line in enumerate(open(filename)):
            if i == lineno - 1:
                return line
    return ''

Untested (I don't have a build quite recent enough).

This is for Challenge 2.  The lineno-1 makes it likely slower than the 
others.  If there was an optional argument to enumerate specifying 
'startat=1', then I might catch up.