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批量修改图片尺寸,并保存指定路径的实现方法

如下所示: import os from PIL import Image filename = os.listdir("D:\\Work\\process\\样本处理\\pol...

python3-flask-3将信息写入日志的实操方法

使用logging模块,记录日志信息 安装模块 pip3 install logging 脚本示例 vim flask_api_logging.py #!/usr/bin/e...

Python代码块及缓存机制原理详解

这篇文章主要介绍了Python代码块及缓存机制原理详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.相同的字符串在Python中...

python模糊图片过滤的方法

最近在做人脸识别清洗样本的工作,发现经过人脸对齐后存在部分图片十分模糊,所以用opencv滤了一下。 原理就是使用了cv2.Laplacian()这个方法,代码如下。图片越模糊,imag...

numpy中的高维数组转置实例

numpy中的高维数组转置实例

numpy中的ndarray很适合数组运算 transpose是用来转置的一个函数,很容易让人困惑,其实它是对矩阵索引顺序的一次调整。原先矩阵是一个三维矩阵,索引顺序是x,y,z,角标...