国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

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

2020-02-23 05:11:04
字體:
來源:轉載
供稿:網友

代碼如下:
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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮安市| 崇州市| 崇州市| 承德市| 铜山县| 铜梁县| 沁水县| 莱西市| 南部县| 增城市| 甘南县| 大方县| 和林格尔县| 七台河市| 石渠县| 贵州省| 黔西| 栖霞市| 溧水县| 扶沟县| 平湖市| 襄樊市| 鲁甸县| 和龙市| 徐闻县| 宝坻区| 麻城市| 孟州市| 丹巴县| 甘德县| 佛山市| 仙游县| 阜平县| 资溪县| 曲靖市| 安阳市| 招远市| 南投县| 黄石市| 霍林郭勒市| 东港市|