python list怎么去重复
简单for循环ids = [1,2,3,3,4,2,3,4,5,6,1]
items = []
for id in ids:
if id not in items:
items.append(id)set方式ids = [1,4,3,3,4,2,3,4,5,6,1]
newIds = list(set(ids))
newIds.sort(key=ids.index) # 修正顺序reduce方式ids = [1,4,3,3,4,2,3,4,5,6,1]
func = lambda x,y:x if y in x else x + [y]
reduce(func, [[], ] + ids)
赞0
踩0