如何按字母顺序对大文本文件进行排序?

Rst*_*voa 6 python sorting

所以我有一个文本文件,我需要按字母顺序排序.输入示例:

This is the first sentence
A sentence here as well
But how do I reorder them?
Run Code Online (Sandbox Code Playgroud)

输出:

A sentence here as well
But how do I reorder them?
This is the first sentence
Run Code Online (Sandbox Code Playgroud)

事情就是这样:这个文件太大了,我没有足够的RAM来实际将它分成列表/数组.我试图使用Python的内置sorted()函数,并且该进程被杀死.

给你一个想法:

wc -l data
21788172 data
Run Code Online (Sandbox Code Playgroud)

Hug*_*ell 5

听起来你需要进行合并排序:将文件分成块,对每个块进行排序,然后将排序后的块合并在一起.请参阅Python类以合并已排序的文件,如何改进?