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

相关文章

浅谈tensorflow中张量的提取值和赋值

浅谈tensorflow中张量的提取值和赋值

tf.gather和gather_nd从params中收集数值,tf.scatter_nd 和 tf.scatter_nd_update用updates更新某一张量。严格上说,tf.ga...

Pandas标记删除重复记录的方法

Pandas提供了duplicated、Index.duplicated、drop_duplicates函数来标记及删除重复记录 duplicated函数用于标记Series中的值、Da...

使用python统计文件行数示例分享

复制代码 代码如下:import time def block(file,size=65536):    while True:  &n...

python实现rsa加密实例详解

python实现rsa加密实例详解 一 代码 import rsa key = rsa.newkeys(3000)#生成随机秘钥 privateKey = key[1]#私钥 pu...

Python+Selenium使用Page Object实现页面自动化测试

  Page Object模式是Selenium中的一种测试设计模式,主要是将每一个页面设计为一个Class,其中包含页面中需要测试的元素(按钮,输入框,标题 等),这样在Se...