美文网首页
python中如何对于元素为字典dict的列表list去重

python中如何对于元素为字典dict的列表list去重

作者: thirsd | 来源:发表于2020-02-23 22:21 被阅读0次

    对于python3

    from functools import reduce
    a_list = [{"a": "1", "b": "2"}, {"a": "1", "b": "3"}, {"a": "1", "b": "2"}]
    reduce_function = lambda x, y: x if y in x else x + [y]
    reduce(reduce_function , [[], ] + a_list)
    
    >>> from functools import reduce
    >>> a_list = [{"a": "1", "b": "2"}, {"a": "1", "b": "3"}, {"a": "1", "b": "2"}]
    >>> reduce_function = lambda x, y: x if y in x else x + [y]
    >>> reduce(reduce_function , [[], ] + a_list)
    [{'a': '1', 'b': '2'}, {'a': '1', 'b': '3'}]
    

    相关文章

      网友评论

          本文标题:python中如何对于元素为字典dict的列表list去重

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