我是靠谱客的博主 无辜狗,这篇文章主要介绍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去掉字符串中重复字符的方法的全部内容,更多相关python去掉字符串中重复字符内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(143)

评论列表共有 0 条评论

立即
投稿
返回
顶部