Python实现字典去除重复的方法示例

yipeiwu_com5年前Python基础

本文实例讲述了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 等等

PS:本站还有两款比较简单实用的在线文本去重复工具,推荐给大家使用:

在线去除重复项工具:
http://tools.jb51.net/code/quchong

在线文本去重复工具:
http://tools.jb51.net/aideddesign/txt_quchong

更多关于Python相关内容可查看本站专题:《Python字典操作技巧汇总》、《Python字符串操作技巧汇总》、《Python常用遍历技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

相关文章

python实现对csv文件的列的内容读取

以下代码测试在python2.7 mac上运行成功 import csv with open('/Users/wangzhao/Downloads/test.csv', 'U')...

Python Pandas 箱线图的实现

Python Pandas 箱线图的实现

各国家用户消费分布 import numpy as np import pandas as pd import matplotlib.pyplot as plt data...

python和bash统计CPU利用率的方法

本文实例讲述了python和bash统计CPU利用率的方法。分享给大家供大家参考。具体如下: 开始的时候写了一个 bash 的实现; 因为最近也在学习 python ,所以就尝试着用 p...

django 邮件发送模块smtp使用详解

前言 在Python中已经内置了一个smtp邮件发送模块,Django在此基础上进行了简单地封装,让我们在Django环境中可以更方便更灵活的发送邮件。 所有的功能都在django.co...

最基础的Python的socket编程入门教程

本文介绍使用Python进行Socket网络编程,假设读者已经具备了基本的网络编程知识和Python的基本语法知识,本文中的代码如果没有说明则都是运行在Python 3.4下。 Pyth...