本文實(shí)例講述了Python實(shí)現(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 等等
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選