On Fri, Apr 26, 2002 at 08:56:31PM -0400, Tim Peters wrote: > The attached g2 is about 60% quicker across the text files I tried it on, > using this timing driver (which sums the time across all interesting inputs; > note that, overall, this is quadratic-time in the number or lines for either > method): measured with your driver script the following code is about 10-20% faster than 'g2' and it gets close to > > Challenge 3: do it faster and with less code. def g3(filename, lineno): if lineno>0: f = file(filename) while lineno>0: read = f.read(1024) count = read.count('\n') lineno-=count or lineno f.close() if lineno<count: return read.split('\n')[lineno+count-1] return '' vertically it's one line less but it stretches a bit horizontally. But it is more portable :-) holger
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