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 保存矩阵为Excel的实现方法

如下所示: def save(data, path): f = xlwt.Workbook() # 创建工作簿 sheet1 = f.add_sheet(u'sheet1',...

Python strip lstrip rstrip使用方法

    注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如: theString = 'saaaay&nb...

Python获取SQLite查询结果表列名的方法

本文实例讲述了Python获取SQLite查询结果表列名的方法。分享给大家供大家参考,具体如下: 获得查询结果表的列名: db = sqlite.connect('data.db')...

python+django+rest框架配置创建方法

python+django+rest框架配置创建方法

安装好所需要的插件和包: python、django、pip等版本如下: 采用Django REST框架3.0 1、在python文件夹下D:\python\Lib\site-pack...

python3.6根据m3u8下载mp4视频

python3.6根据m3u8下载mp4视频

需要下载某网站的视频,chrome浏览器按F12打开开发者模式,发现视频链接是以"blob:http"开头的链接,打开这个链接后找不到网页,网上查了下,找到了下载方法,在这里做个记录,如...