手机
当前位置:查字典教程网 >脚本专栏 >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和shell变量互相传递的几种方法

python每次处理固定个数的字符的方法总结

python 字符串格式化代码

Python 匹配任意字符(包括换行符)的正则表达式写法

python爬取网站数据保存使用的方法

python函数返回多个值的示例方法

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

python三元运算符实现方法

Python 字符串定义

精品推荐
分类导航