Python實現(xiàn)字典去除重復的方法示例
本文實例講述了Python實現(xiàn)字典去除重復的方法。分享給大家供大家參考,具體如下:
#!/usr/bin/env python
# encoding: utf-8
#字典去重小代碼
import sys
import os
import platform
try:
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:本站還有兩款比較簡單實用的在線文本去重復工具,推薦給大家使用:
在線去除重復項工具:
http://tools.jb51.net/code/quchong
在線文本去重復工具:
http://tools.jb51.net/aideddesign/txt_quchong
更多關于Python相關內容可查看本站專題:《Python字典操作技巧匯總》、《Python字符串操作技巧匯總》、《Python常用遍歷技巧總結》、《Python數(shù)據(jù)結構與算法教程》、《Python函數(shù)使用技巧總結》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
相關文章
談一談數(shù)組拼接tf.concat()和np.concatenate()的區(qū)別
今天小編就為大家分享一篇談談數(shù)組拼接tf.concat()和np.concatenate()的區(qū)別,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
python基于multiprocessing的多進程創(chuàng)建方法
這篇文章主要介紹了python基于multiprocessing的多進程創(chuàng)建方法,實例分析了multiprocessing模塊操作進程的相關技巧,需要的朋友可以參考下2015-06-06

