手机
当前位置:查字典教程网 >脚本专栏 >python >python去掉字符串中重复字符的方法
python去掉字符串中重复字符的方法
摘要:复制代码代码如下:Iforderdoesnotmatter,youcanuse"".join(set(foo))set()willcreat...

复制代码 代码如下:

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去掉字符串中重复字符的方法】相关文章:

python 不关闭控制台的实现方法

Python转码问题的解决方法

Python 字符串定义

python 将字符串转换成字典dict

python回调函数的使用方法

python 获取本机ip地址的两个方法

python和shell变量互相传递的几种方法

python实现网页链接提取的方法分享

python读取注册表中值的方法

Python去掉字符串中空格的方法

精品推荐
分类导航