Seek the one billionth line in a file containing 3 billion lines.
Bjoern Schliessmann
usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Wed Aug 8 07:55:11 EDT 2007
Peter Otten wrote:
> n = 10**9 - 1
> assert n < sys.maxint
> f = open(filename)
> wanted_line = itertools.islice(f, n, None).next()
>
> should do slightly better than your implementation.
It will do vastly better, at least in memory usage terms, because
there is no memory eating range call.
Regards,
Björn
--
BOFH excuse #31:
cellular telephone interference
More information about the Python-list
mailing list