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

相关文章

Windows系统下多版本pip的共存问题详解

Windows系统下多版本pip的共存问题详解

前言 可能很多人一看到这个标题直接就关闭了,这么简单和low的问题有必要说出来吗?一看就知道是个Python的小白。如果你是这么想的话,那么就没有必要看下去了,因为对你来说也没有...

python 实现在tkinter中动态显示label图片的方法

python 实现在tkinter中动态显示label图片的方法

在编程中我们往往会希望能够实现这样的操作:点击Button,选择了图片,然后在窗口中的Label处显示选到的图片。那么这时候就需要如下代码: from tkinter import...

使用k8s部署Django项目的方法步骤

接触了一下docker和k8s,感觉是非常不错的东西。能够方便的部署线上环境,而且还能够更好的利用机器的资源,感觉是以后的大趋势。最近刚好有一个基于django的项目,所以就把这个项目打...

浅谈Tensorflow 动态双向RNN的输出问题

浅谈Tensorflow 动态双向RNN的输出问题

tf.nn.bidirectional_dynamic_rnn()函数:def bidirectional_dynamic_rnn(   cell_fw,&...

Python线程中对join方法的运用的教程

join 方法:阻塞线程 , 直到该线程执行完毕 因此  ,可以对join加一个超时操作 , join([timeout]),超过设置时间,就不再阻塞线程 jion加上还有一个...