当前位置: 移动技术网 > IT编程>脚本编程>Python > python去掉字符串中重复字符的方法

python去掉字符串中重复字符的方法

2019年04月01日  | 移动技术网IT编程  | 我要评论

tokyo hot n0632,中国邮政快递,丘比特的圈套下载

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网