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,字符串
0
投稿

猜你喜欢

  • 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
  • selenium+python自动化测试之环境搭建

    2022-05-15 13:51:32
  • 利用MySQL加密函数保护Web网站敏感数据

    2008-12-17 16:11:00
  • Mac版Python3安装/升级的方式

    2021-03-07 13:24:40
  • 如何使用五行Python代码轻松实现批量抠图

    2023-10-06 08:05:20
  • Python办公自动化从Excel中计算整理数据并写入Word

    2021-12-19 03:22:35
  • 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
  • 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
  • eslint常见的一些报错及解决方法

    2024-05-11 09:09:32
  • vue-quill-editor实现图片上传功能

    2024-04-30 10:22:40
  • Python带动态参数功能的sqlite工具类

    2022-10-02 14:05:15
  • asp之家 网络编程 m.aspxhome.com