对于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'}]
网友评论