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

相关文章

python3利用Dlib19.7实现人脸68个特征点标定

python3利用Dlib19.7实现人脸68个特征点标定

0.引言 利用Dlib官方训练好的模型“shape_predictor_68_face_landmarks.dat”进行68点标定,利用OpenCv进行图像化处理,在人脸上画出68个点,...

python超简单解决约瑟夫环问题

本文实例讲述了python超简单解决约瑟夫环问题的方法。分享给大家供大家参考。具体分析如下: 约瑟环问题大家都熟悉。题目是这样的。一共有三十个人,从1-30依次编号。每次隔9个人就踢出去...

python利用MethodType绑定方法到类示例代码

前言 本文主要给大家介绍了关于python用MethodType绑定方法到类的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 对python中MethodTyp...

python查看zip包中文件及大小的方法

本文实例讲述了python查看zip包中文件及大小的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python import zipfile z =...

对Python实现简单的API接口实例讲解

对Python实现简单的API接口实例讲解

get方法 代码实现 # coding:utf-8 import json from urlparse import parse_qs from wsgiref.simple_s...