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

源码网商城

python中对list去重的多种方法

  • 时间:2021-02-26 13:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python中对list去重的多种方法
今天遇到一个问题,在同事随意的提示下,用了 itertools.groupby 这个函数。不过这个东西最终还是没用上。 问题就是对一个list中的新闻id进行去重,去重之后要保证顺序不变。 [b]直观方法[/b] 最简单的思路就是:
[url=http://docs.python.org/2/library/itertools.html#itertools.groupby]http://docs.python.org/2/library/itertools.html#itertools.groupby[/url] [b]网友补充:用reduce[/b] 网友reatlk留言给了另外的解决方案。我补充并解释到这里:
[url=http://docs.python.org/2/library/functions.html#reduce]http://docs.python.org/2/library/functions.html#reduce[/url]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部