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

yipeiwu_com5年前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中的引用和拷贝浅析

If an object's value can be modified, the object is said to be mutable. If the value cannot b...

django允许外部访问的实例讲解

1、关闭防火墙 service iptables stop 2、设置django 开开启django时,使用0.0.0.0:xxxx,作为ip和端口例如: python ma...

Python中栈、队列与优先级队列的实现方法

前言 栈、队列和优先级队列都是非常基础的数据结构。Python作为一种“编码高效”的语言,对这些基础的数据结构都有比较好的实现。在业务需求开发过程中,不应该重复造轮子,今天就来看看些数据...

Python实现115网盘自动下载的方法

本文实例讲述了Python实现115网盘自动下载的方法。分享给大家供大家参考。具体实现方法如下: 实例中的1.txt,是网页http://bbs.pediy.com/showthread...

基于wxPython的GUI实现输入对话框(2)

基于wxPython的GUI实现输入对话框(2)

接着上一篇基于wxPython的GUI输入对话框1,继续学习。 在程序输入中,有时会要求同时改变多个参数值,而且类型也不尽相同, 这时TextEntryDialog就显得不适用了.WxI...