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连接、操作mongodb数据库的方法实例详解

本文实例讲述了python连接、操作mongodb数据库的方法。分享给大家供大家参考,具体如下: 数据库连接 from pymongo import MongoClient imp...

django使用xadmin的全局配置详解

django使用xadmin的全局配置详解

这篇主要写一些xadmin一些基础的全局设置 主题设置 首先需要在创建好的app中新建一个adminx.py的文件,然后添加代码 # _*_ coding: utf-8 _*_ i...

解决python中导入win32com.client出错的问题

准备写一个操作Excel脚本却在导入包的时候出现了一个小问题 导入包 from Tkinter import Tk from time import sleep, ctime fro...

python基础教程之获取本机ip数据包示例

python基础教程之获取本机ip数据包示例

这几天用到了raw socket,用python写了些demo程序,这里记录下。 首先我们看一个简单的sniffer程序: 复制代码 代码如下:#! /usr/bin/python# c...

python打开使用的方法

python打开使用的方法

python怎么打开使用? 1、首先需要打开电脑的桌面,如图所示,并按开始的快捷键点击安装好的python3.6程序进入。 2、然后点击进入之后,如图所示,可以看到页面上面的三个大于号...