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.6+Django2.0以上 xadmin站点的配置和使用教程图解

Python3.6+Django2.0以上 xadmin站点的配置和使用教程图解

1. xadmin的介绍 django自带的admin站点虽然功能强大,但是界面不是很好看。而xadmin界面好看,功能更强大,并完全支持Bootstrap主题模板。xadmin内置了丰...

画pytorch模型图,以及参数计算的方法

画pytorch模型图,以及参数计算的方法

刚入pytorch的坑,代码还没看太懂。之前用keras用习惯了,第一次使用pytorch还有些不适应,希望广大老司机多多指教。 首先说说,我们如何可视化模型。在keras中就一句话,k...

python实现感知器算法(批处理)

python实现感知器算法(批处理)

本文实例为大家分享了Python感知器算法实现的具体代码,供大家参考,具体内容如下 先创建感知器类:用于二分类 # -*- coding: utf-8 -*- import nu...

python实现控制台打印的方法

如下所示: #!/usr/bin/env python import os import sys class CConsole: M_MAP_COLOR = {\ 'COLO...

TensorFlow实现RNN循环神经网络

TensorFlow实现RNN循环神经网络

RNN(recurrent neural Network)循环神经网络 主要用于自然语言处理(nature language processing,NLP) RNN主要用途是处理和预测序...