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

相关文章

在django admin中添加自定义视图的例子

django admin提供了完善的用户管理和数据模型管理,方便实用。研究了一下在admin里面添加自己的页面。 在admin.py里继承django.contrib.admin.Mod...

使用selenium模拟登录解决滑块验证问题的实现

使用selenium模拟登录解决滑块验证问题的实现

本次主要是使用selenium模拟登录网页端的TX新闻,本来最开始是模拟请求的,但是某一天突然发现,部分账号需要经过滑块验证才能正常登录,如果还是模拟请求,需要的参数太多了,找的心累。不...

Python2.X/Python3.X中urllib库区别讲解

本文介绍urllib库在不同版本的Python中的变动,并以Python3.X讲解urllib库的相关用法。 urllib库对照速查表 Python2.X...

Python中datetime常用时间处理方法

常用时间转换及处理函数: import datetime # 获取当前时间 d1 = datetime.datetime.now() print d1 # 当前时间加上半小时 d2...

Linux环境下MySQL-python安装过程分享

1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本   python -V   检查python版本 2. 安装mysql...