Python实现字典去除重复的方法示例
作者:无法自拔 时间:2021-02-24 21:52:14
本文实例讲述了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,字典,去除重复
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python判断字符串的前两个字母是否是"id"的示例代码
2021-05-02 20:39:12
Django开发中的日志输出的方法
2023-02-24 07:37:17
Python实现单例模式的四种方式详解
2023-07-12 03:07:43
![](https://img.aspxhome.com/file/2023/5/97345_0s.png)
手把手教你用python抢票回家过年(代码简单)
2023-07-13 22:46:02
![](https://img.aspxhome.com/file/2023/0/118100_0s.jpg)
利用Python实现热力图的绘制
2021-11-07 12:02:47
![](https://img.aspxhome.com/file/2023/8/82578_0s.jpg)
Python实现自动清理电脑垃圾文件详解
2023-05-18 00:50:22
![](https://img.aspxhome.com/file/2023/7/90467_0s.png)
Js的MessageBox
2008-05-16 10:25:00
Python TypeError: ‘float‘ object is not subscriptable错误解决
2023-09-13 05:33:02
![](https://img.aspxhome.com/file/2023/9/62249_0s.png)
Python OpenCV超详细讲解调整大小与图像操作的实现
2022-07-09 21:16:27
![](https://img.aspxhome.com/file/2023/2/105582_0s.png)
PHP实现PDF转图片的方法详解
2023-05-26 19:59:51
python3中数组逆序输出方法
2022-08-12 22:25:56
python 调用API接口 获取和解析 Json数据
2022-01-24 17:57:15
对python 匹配字符串开头和结尾的方法详解
2023-02-03 23:45:40
JavaScript 获取客户端计算机硬件及系统信息
2009-01-13 17:59:00
![](https://img.aspxhome.com/file/UploadPic/20091/13/200901081050518738-49s.gif)
python3在各种服务器环境中安装配置过程
2021-10-27 22:49:55
python实现将视频按帧读取到自定义目录
2023-07-15 01:24:11
pygame实现键盘的连续监控
2023-09-26 11:17:10
详解selenium + chromedriver 被反爬的解决方法
2022-03-20 18:40:46
Python + selenium + crontab实现每日定时自动打卡功能
2021-06-10 19:45:42
![](https://img.aspxhome.com/file/2023/6/84926_0s.png)
泛泛而谈界面中的斑马纹设计
2010-07-15 12:59:00
![](https://img.aspxhome.com/file/UploadPic/20107/15/bm-001-76s.jpg)