列表去重

2015-08-18 0 601
列表去重
#!/usr/bin/env python

try: set
except NameError: from sets import Set as set
def unique(s): 

    try:
        return list(set(s))
    except:
        pass
    t = list(s)
    try:
        t.sort()
    except typeError:
        del t
    else:
        return [x for i,x in enumerate(t) if not i or x !=t[i-1]]
    u = []
    for x in s:
        if x not in u:
            u.append(x)
    return u
l=[1,1,2,3,4,22,33,33]
print unique(l)

遇见资源网 python 列表去重 http://www.ox520.com/15700.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务