python去掉字符串中重复字符的方法

yipeiwu_com6年前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实现提取谷歌音乐搜索结果的方法。分享给大家供大家参考。具体如下: Python的简单脚本,用于提取谷歌音乐搜索页面中的歌曲信息,包括歌曲名,作者,专辑名,现在链...

用Anaconda安装本地python包的方法及路径问题(图文)

用Anaconda安装本地python包的方法及路径问题(图文)

Anaconda确实带来了很多方便,但是之前也过多的依赖了conda自带的一键下载python包的功能。这不,这几天突然要用FastFM这个包,无奈conda里没有,于是只能从githu...

python项目对接钉钉SDK的实现

python项目对接钉钉SDK的实现

 钉钉SDK 对接sdk还是遇到不少问题的 钉钉python版SDK文档地址:https://dingtalk-sdk.readthedocs.io/zh_CN/lates...

python正则表达式匹配[]中间为任意字符的实例

如下所示: result = re.search('^\[[\S\s]*\]$',str) print(result) print(result.group()) <_sre....

Python获取邮件地址的方法

本文实例讲述了Python获取邮件地址的方法。分享给大家供大家参考。具体实现方法如下: import email.Utils   def getCleanMailAddress(st...