Python实现字典去除重复的方法示例
本文实例讲述了Python实现字典去除重复的方法。分享给大家供大家参考,具体如下:
#!/usr/bin/envpython
#encoding:utf-8
#字典去重小代码
importsys
importos
importplatform
try:
pass
except:
print'''youhavesomethingwrongthisisasimplejiaoben'''
sys.exit()
why='why.txt'
foriinxrange(len(sys.argv)):
if(i>=1):
other=sys.argv[i]
ifos.path.exists(other):
pass
else:
printother+'filenotfind'
sys.exit()
if'Windows'inplatform.system():
os.system("type"+other+">>"+why)
else:
os.system("cat"+other+">>"+why)
yuan=open('why.txt','r')
dirc=open('whynot.txt','w')
forlineinset(yuan.readlines()):
ifline==''orline=='\r\n':
pass
else:
dirc.writelines(line)
很简单的思路把文件放入到why.txt中然后再去重得到whynot.txt
Usage:quchong.py1.txt2.txt3.txt等等
PS:本站还有两款比较简单实用的在线文本去重复工具,推荐给大家使用:
在线去除重复项工具:
http://tools.jb51.net/code/quchong
在线文本去重复工具:
http://tools.jb51.net/aideddesign/txt_quchong
更多关于Python相关内容可查看本站专题:《Python字典操作技巧汇总》、《Python字符串操作技巧汇总》、《Python常用遍历技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。