python去掉字符串中重复字符的方法
更新时间:2014年02月27日 09:35:09 作者:
这篇文章主要介绍了python去掉字符串中重复字符的方法,需要的朋友可以参考下
复制代码 代码如下:
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机器学习算法库scikit-learn学习之决策树实现方法详解
这篇文章主要介绍了Python机器学习算法库scikit-learn学习之决策树实现方法,结合实例形式分析了决策树算法的原理及使用sklearn库实现决策树的相关操作技巧,需要的朋友可以参考下2019-07-07


最新评论