源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-02-15 04:02 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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 等等 [b]PS:本站还有两款比较简单实用的在线文本去重复工具,推荐给大家使用:[/b] [b]在线去除重复项工具: [/b][url=http://tools.jb51.net/code/quchong]http://tools.jb51.net/code/quchong[/url] [b]在线文本去重复工具: [/b][url=http://tools.jb51.net/aideddesign/txt_quchong]http://tools.jb51.net/aideddesign/txt_quchong[/url] 更多关于Python相关内容可查看本站专题:《[url=http://www.1sucai.cn/Special/670.htm]Python字典操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/636.htm]Python字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/699.htm]Python常用遍历技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/663.htm]Python数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/642.htm]Python函数使用技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/520.htm]Python入门与进阶经典教程[/url]》 希望本文所述对大家Python程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部