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 等等

转载于:https://www.cnblogs.com/jsq16/p/5941978.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值