Python实现字典去重的脚本示例与在线工具推荐

听雨眠
听雨眠
发布时间:2026-10-13 | 2人浏览过
原创

本文介绍了一个使用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)

该脚本逻辑简单:将指定文件内容合并后去重,输出到whynot.txt。用法为:quchong.py 1.txt 2.txt 3.txt等。

此外,本站还提供两款简单实用的在线文本去重工具,推荐给大家使用:

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

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

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

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

相关标签:

本站声明

本文内容仅供参考,不代表本站观点。转载或引用请注明出处。如发现内容问题,请通过联系我们页面反馈。

Python 相关产品和应用

全部下载

专题列表