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,字典,去除重复


猜你喜欢
浅谈python输出列表元素的所有排列形式
2023-02-10 11:09:39
pytorch实现线性拟合方式
2021-12-30 01:50:32

MySQL Slave 触发 oom-killer解决方法
2024-01-20 14:44:35
MySQL 分组查询和聚合函数
2024-01-23 00:51:41
Python selenium文件上传方法汇总
2022-12-01 04:47:29
Vue的生命周期一起来看看
2024-05-02 17:03:21

Oracle 10g 服务器端安装预备步骤(详细图文教程)
2024-01-13 07:39:57

Python针对给定字符串求解所有子序列是否为回文序列的方法
2022-04-30 01:17:36

Python使用re模块验证危险字符
2023-10-29 13:46:55
asp自动补全html标签自动闭合(正则表达式)
2013-06-01 20:01:59
浅析mysql迁移到clickhouse的5种方法
2024-01-27 21:51:47

Django 通过JS实现ajax过程详解
2023-08-17 08:00:46
python编程控制Android手机操作技巧示例
2021-12-01 07:59:05

解决pytorch报错:AssertionError: Invalid device id的问题
2021-05-15 16:13:42
eclipse创建python项目步骤详解
2021-01-15 00:40:47

MySql存储过程与函数详解
2024-01-13 16:32:56

学习ASP和编程的28个观点
2008-06-27 12:57:00
php flv视频时间获取函数
2023-09-04 13:41:48
在Matplotlib图中插入LaTex公式实例
2023-09-05 12:23:38

mysql 超大数据/表管理技巧
2024-01-16 22:14:05