Remove Duplicates from Text File

前端 未结 7 1112
梦毁少年i
梦毁少年i 2020-12-17 05:34

I want to remove duplicate word from a text file.

i have some text file which contain such like following:

None_None

ConfigHandler_56663624
ConfigHa         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 05:59

    Here is a simple solution using sets to remove the duplicates from the text file.

    lines = open('workfile.txt', 'r').readlines()
    
    lines_set = set(lines)
    
    out  = open('workfile.txt', 'w')
    
    for line in lines_set:
        out.write(line)
    

提交回复
热议问题