您的位置:首页 > 其它

不打乱顺序的情况下去除数组中的重复元素

2015-01-14 18:03 393 查看
def unique_list(xs):
seen = set()
# not seen.add(x) here acts to make the code shorter without using if statements, seen.add(x) always returns None.
return [x for x in xs if x not in seen and not seen.add(x)]
def unique(l):
    seen = set()
    u_list = []
    for x in l:
        if not x in seen:
            u_list.append(x)
        seen.add(x)
    return u_list
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: