源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-11-03 14:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python去掉字符串中重复字符的方法
[u]复制代码[/u] 代码如下:
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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部