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

相关文章

推荐10款最受Python开发者欢迎的Python IDE

推荐10款最受Python开发者欢迎的Python IDE

Python 非常易学,强大的编程语言。Python 包括高效高级的数据结构,提供简单且高效的面向对象编程。 Python 的学习过程少不了 IDE 或者代码编辑器,或者集成的开发编辑器...

从Python程序中访问Java类的简单示例

from jnius import autoclass >>> Stack = autoclass('java.util.Stack') >>>...

python django框架中使用FastDFS分布式文件系统的安装方法

python django框架中使用FastDFS分布式文件系统的安装方法

一、安装FastDFS 1-1:执行docker命令安装 # 安装tracker docker run -dti --network=host --name tracker -v /...

django限制匿名用户访问及重定向的方法实例

前言 大家应该都遇到过,在某些页面中,我们不希望匿名用户能够访问,例如个人页面等,这种页面只允许已经登录的用户去访问,在django中,我们也有比较多的方式去实现。 最简单的,我们在v...

python数据批量写入ScrolledText的优化方法

如下所示: for i in data[::-1]: self.maintenance_text.insert(tk.END, str(i['payload']) + '\n\n'...