【转】python list 保持顺序去重复

2015-09-01  本文已影响0人  r_b_prince
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]
ids = list(set(ids))
上一篇下一篇

猜你喜欢

热点阅读