本文實例講述了Python實現(xiàn)字典去除重復(fù)的方法。分享給大家供大家參考,具體如下:
#!/usr/bin/env python# encoding: utf-8#字典去重小代碼import sysimport osimport platformtry: pass except: print '''you have something wrong this is a simple jiaoben ''' sys.exit()why = 'why.txt'for i in xrange(len(sys.argv)): if(i>=1): other = sys.argv[i] if os.path.exists(other): pass else: print other + ' file not find' sys.exit() if 'Windows' in platform.system(): os.system("type "+other+" >> "+why) else: os.system("cat "+other+" >> "+why)yuan = open('why.txt','r')dirc = open('whynot.txt','w')for line in set(yuan.readlines()): if line == '' or line == '/r/n': pass else: dirc.writelines(line)很簡單的思路 把文件放入到why.txt中 然后再去重得到whynot.txt
Usage: quchong.py 1.txt 2.txt 3.txt 等等
PS:本站還有兩款比較簡單實用的在線文本去重復(fù)工具,推薦給大家使用:
在線去除重復(fù)項工具:
http://tools.jb51.net/code/quchong
在線文本去重復(fù)工具:
http://tools.jb51.net/aideddesign/txt_quchong
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python字典操作技巧匯總》、《Python字符串操作技巧匯總》、《Python常用遍歷技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》及《Python入門與進階經(jīng)典教程》
希望本文所述對大家Python程序設(shè)計有所幫助。
新聞熱點
疑難解答