So I have a text file and I need to sort the lines alphabetically. Example input:
This is the first sentence
A sentence here as well
But how do I reorder them?
Output:
A sentence here as well
But how do I reorder them?
This is the first sentence
Here's the thing: This file is so large, I don't have enough RAM to actually split it into a list/array. I tried to use Python's built-in sorted() function and the process got killed.
To give you an idea:
wc -l data
21788172 data
It sounds like you need to do a merge-sort: divide the file into blocks, sort each block, then merge the sorted blocks back together. See Python class to merge sorted files, how can this be improved?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With