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实现简单的API接口实例讲解

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

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

Python基于Matplotlib库简单绘制折线图的方法示例

Python基于Matplotlib库简单绘制折线图的方法示例

本文实例讲述了Python基于Matplotlib库简单绘制折线图的方法。分享给大家供大家参考,具体如下: Matplotlib画折线图,有一些离散点,想看看这些点的变动趋势: im...

python多进程重复加载的解决方式

flask多进程会引起重复加载, 解决方法:把耗资源的加载挪到函数里面或者类里面,就不会重复加载资源了。 测试发现,不是flask引起的,是多进程会引起重复加载python文件。 把fl...

python创建线程示例

复制代码 代码如下:import threadingfrom time import sleep def test_func(id):    for i i...

详解Python3中setuptools、Pip安装教程

1、安装setuptools 命令如下: wget --no-check-certificate https://pypi.python.org/packages/source/s/...