python去掉字符串中重复字符的方法
时间:2022-11-23 09:17:35
If order does not matter, you can use
"".join(set(foo))
set() will create a set of unique letters in the string, and "".join() will join the letters back to a string in arbitrary order.
If order does matter, you can use collections.OrderedDict in Python 2.7:
from collections import OrderedDict
foo = "mppmt"
print "".join(OrderedDict.fromkeys(foo))
printing
mpt
标签:python,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现读取TXT文件数据并存进内置数据库SQLite3的方法
2021-03-01 14:14:27
解决iframe的frameborder在chrome/ff/ie下的差异
2023-08-09 00:23:24
python模块shutil函数应用示例详解教程
2022-09-29 02:07:36
![](https://img.aspxhome.com/file/2023/2/110242_0s.png)
selenium+python自动化测试之环境搭建
2022-05-15 13:51:32
![](https://img.aspxhome.com/file/2023/1/75901_0s.png)
利用MySQL加密函数保护Web网站敏感数据
2008-12-17 16:11:00
Mac版Python3安装/升级的方式
2021-03-07 13:24:40
如何使用五行Python代码轻松实现批量抠图
2023-10-06 08:05:20
![](https://img.aspxhome.com/file/2023/6/117576_0s.jpg)
Python办公自动化从Excel中计算整理数据并写入Word
2021-12-19 03:22:35
![](https://img.aspxhome.com/file/2023/9/97409_0s.png)
MySQL高级查询方法之记录查询
2010-06-20 14:48:00
Node.js Domain 模块实例详解
2024-05-08 09:35:15
pycharm 关闭search everywhere的解决操作
2022-04-20 02:46:50
![](https://img.aspxhome.com/file/2023/8/131748_0s.jpg)
PHP生成sitemap.xml地图函数
2024-06-05 09:23:16
MySQL用户和权限及破解root口令的方法示例
2024-01-23 23:12:16
firefox浏览器不支持innerText的解决方法
2024-04-10 10:51:42
浅谈在JupyterNotebook下导入自己的模块的问题
2023-03-16 11:28:36
python中requests模块的使用方法
2021-12-27 23:16:29
优化SQL Server的内存占用之执行缓存
2024-01-12 19:13:27
![](https://img.aspxhome.com/file/2023/4/94444_0s.gif)
eslint常见的一些报错及解决方法
2024-05-11 09:09:32
![](https://img.aspxhome.com/file/2023/0/126580_0s.png)
vue-quill-editor实现图片上传功能
2024-04-30 10:22:40
Python带动态参数功能的sqlite工具类
2022-10-02 14:05:15