美文网首页
Python 列表去重

Python 列表去重

作者: 酱油攻城狮 | 来源:发表于2018-01-29 19:58 被阅读0次

    1、去重不保持原来的顺序:

    ret_list = list(set(list))
    

    2、去重保持原顺序(reduce):

    list_o = [1,2,3,3,5,5,6,7,4,9,0]
    func =lambda x,y :  x if y in x else x + [y]
    list_t = reduce( func, [[],  ] + list_o)
    #list_t=[1,2,3,5,6,7,4,9,0]
    

    3、list元素是字典,去重

    f = lambda x,y:x if y in x else x + [y]
    data_list = reduce(f, [[], ] + data_list)
    

    相关文章

      网友评论

          本文标题:Python 列表去重

          本文链接:https://www.haomeiwen.com/subject/yeefzxtx.html