比如有个 txt 文本,一共有 33W 行文字,以行作为单位,去重,我应该怎么写效率会比较高呢?
我目前用的普通的方法,发现耗时比较长
我列出我目前的方法
with open('/Users/lizhao/Downloads/aboutchinese.dict.yaml') as f:
for i in f.readlines():
if i == '\n':
continue
if i not in oldList:
oldList.append(i)
with open('tmp.txt','w') as g:
g.writelines(oldList)
代码渣,请轻喷