手机
当前位置:查字典教程网 >脚本专栏 >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 输出一个两行字符的变量

Python中使用中文的方法

python 中文字符串的处理实现代码

python中文乱码的解决方法

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

python 字符串split的用法分享

python回调函数的使用方法

精品推荐
分类导航