merge sort in python

后端 未结 3 1575
栀梦
栀梦 2021-02-06 19:26

basically I have a bunch of files containing domains. I\'ve sorted each individual file based on its TLD using .sort(key=func_that_returns_tld)

now that I\'ve done that

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 20:11

    Unless your file is incomprehensibly huge, it will fit into memory.

    Your pseudo-code is hard to read. Please indent your pseudo-code correctly. The final "loop by reading next line" makes no sense.

    Basically, it's this.

    all_data= []
    for f in list_of_files:
        with open(f,'r') as source:
            all_data.extend( source.readlines() )
    all_data.sort(... whatever your keys are... )
    

    You're done. You can write all_data to a file, or process it further or whatever you want to do with it.

提交回复
热议问题