Sorting Large File (Code/Performance)
Stefan Behnel
stefan.behnel-n05pAM at web.de
Thu Jan 24 16:39:57 EST 2008
Stefan Behnel wrote:
> Ira.Kovac at gmail.com wrote:
>>> What are you going to do with it after it's sorted?
>> I need to isolate all lines that start with two characters (zz to be
>> particular)
>
> "Isolate" as in "extract"? Remove the rest?
>
> Then why don't you extract the lines first, without sorting the file? (or sort
> it afterwards if you still need to). That would heavily cut down your memory
> footprint.
Just for fun, this is what I meant:
for utf8_line in open(filename, 'rb'):
if utf8_line.startswith('zz'):
print utf8_line
Stefan
More information about the Python-list
mailing list