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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

无法自拔   2021-03-23 我要评论
想了解Python实现字典去除重复的方法示例的相关内容吗,无法自拔在本文为您仔细讲解Python字典去除重复的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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.softyun.net/code/quchong

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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们