A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2002-April/023701.html below:

[Python-Dev] Use for enumerate()

[Python-Dev] Use for enumerate() [Python-Dev] Use for enumerate()Greg Ball gball@cfa.harvard.edu
Fri, 26 Apr 2002 23:13:41 -0400 (EDT)
On Fri, 26 Apr 2002, Guido van Rossum wrote:


>     def getline(filename, lineno):
> 	if lineno < 1:
> 	    return ''
> 	lineno -= 1
> 	f = open(filename)
> 	for i, line in enumerate(f):
> 	    if i == lineno:
> 		break
> 	else:
> 	    line = ''
> 	f.close()
> 	return line
> 
> 
> Challenge 2: do it with less code.

     def getline(filename, lineno):
 	if lineno < 1:
 	    return ''
 	f = open(filename)
 	for line in f:
 	    lineno -= 1
 	    if not lineno:
 		break
 	else:
 	    line = ''
 	f.close()
 	return line


--
Greg Ball










RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4