ids = [1,2,3,3,4,2,3,4,5,6,1]
news_ids = []
for id in ids:
if id not in news_ids:
news_ids.append(id)
print news_ids ids = [1,4,3,3,4,2,3,4,5,6,1] ids = list(set(ids))
ids = [1,4,3,3,4,2,3,4,5,6,1] news_ids = list(set(ids)) news_ids.sort(ids.index)
ids = [1,4,3,3,4,2,3,4,5,6,1] ids.sort() it = itertools.groupby(ids) for k, g in it: print k
In [5]: ids = [1,4,3,3,4,2,3,4,5,6,1] In [6]: func = lambda x,y:x if y in x else x + [y] In [7]: reduce(func, [[], ] + ids) Out[7]: [1, 4, 3, 2, 5, 6]
更多Python对list列表结构中的值进行去重相关文章请关注PHP中文网!
查看更多关于Python对list列表结构中的值进行去重的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did85845