python 去掉list中的重复元素
def f1(seq): 
    # not order preserving 
    set = {} 
    map(set.__setitem__, seq, []) 
    return set.keys()

def f2(seq): 
    # order preserving 
    checked = [] 
    for e in seq: 
        if e not in checked: 
            checked.append(e) 
    return checked

def f3(seq): 
    # Not order preserving 
    keys = {} 
    for e in seq: 
        keys[e] = 1 
    return keys.keys()

def f4(seq): 
    # order preserving 
    noDupes = [] 
    [noDupes.append(i) for i in seq if not noDupes.count(i)] 
    return noDupes

def f5(seq, idfun=None): 
    # order preserving 
    if idfun is None: 


def idfun(x): return x 
    seen = {} 
    result = [] 
    for item in seq: 
        marker = idfun(item) 
        # in old Python versions: 
        # if seen.has_key(marker) 
        # but in new ones: 
        if marker in seen: continue 
        seen[marker] = 1 
        result.append(item) 
    return result

def f6(seq): 
    # Not order preserving     
    set = Set(seq) 
    return list(set)


阅读更多
文章标签: python list
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

python 去掉list中的重复元素

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭