手机
当前位置:查字典教程网 >脚本专栏 >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每次处理固定个数的字符的方法总结

Python转码问题的解决方法

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

精品推荐
分类导航