Posted in Python onJuly 31, 2017
本文实例讲述了Python实现字典去除重复的方法。分享给大家供大家参考,具体如下:
#!/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 等等
Python实现字典去除重复的方法示例
- Author -
无法自拔声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@