read lines
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Tue Dec 4 11:04:36 EST 2007
Peter Otten a écrit :
> Bruno Desthuilliers wrote:
>
>> # You don't need to read the whole file in memory
>
>> lines1, lines2 = tee(infile)
>> print min(extract_numbers(lines1)), max(extract_numbers(lines2))
>
> tee() internally maintains a list of items that were seen by
> one but not all of the iterators returned. Therefore after calling min()
> and before calling max() you have a list of one float per line in memory
> which is quite close conceptually to reading the whole file in memory.
>
> If you want to use memory efficiently, stick with the for-loop.
Indeed - I should have specified that the second version was not
necesseraly better wrt/ either perfs and/or resources usage. Thanks for
having made this point clear.
More information about the Python-list
mailing list