python 高效去重復(fù) 支持GB級(jí)別大文件的示例代碼
如下所示:
#coding=utf-8 import sys, re, os def getDictList(dict): regx = '''[\w\~`\!\@\#\$\%\^\&\*\(\)\_\-\+\=\[\]\{\}\:\;\,\.\/\<\>\?]+''' with open(dict) as f: data = f.read() return re.findall(regx, data) def rmdp(dictList): return list(set(dictList)) def fileSave(dictRmdp, out): with open(out, 'a') as f: for line in dictRmdp: f.write(line + '\n') def main(): try: dict = sys.argv[1].strip() out = sys.argv[2].strip() except Exception, e: print 'error:', e me = os.path.basename(__file__) print 'usage: %s <input> <output>' %me print 'example: %s dict.txt dict_rmdp.txt' %me exit() dictList = getDictList(dict) dictRmdp = rmdp(dictList) fileSave(dictRmdp, out) if __name__ == '__main__': main()
以上這篇python 高效去重復(fù) 支持GB級(jí)別大文件的示例代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Pytorch中的數(shù)據(jù)轉(zhuǎn)換Transforms與DataLoader方式
這篇文章主要介紹了Pytorch中的數(shù)據(jù)轉(zhuǎn)換Transforms與DataLoader方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02

Python實(shí)現(xiàn)數(shù)據(jù)地址實(shí)體抽取

Python實(shí)現(xiàn)程序判斷季節(jié)的代碼示例

python+selenium實(shí)現(xiàn)QQ郵箱自動(dòng)發(fā)送功能

vscode搭建python Django網(wǎng)站開發(fā)環(huán)境的示例

Python網(wǎng)絡(luò)編程基于多線程實(shí)現(xiàn)多用戶全雙工聊天功能示例