手机
当前位置:查字典教程网 >脚本专栏 >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 获取本机ip地址的两个方法

python二叉树遍历的实现方法

python三元运算符实现方法

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

python 字符串split的用法分享

python调用shell的方法

python实现排序算法

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

精品推荐
分类导航