https://blog.csdn.net/hng1992/article/details/89642251

 

 

 

from functools import reduce

data_list = [{"a": "123", "b": "321"}, {"a": "123", "b": "321"}, {"b": "321", "a": "123"}]
run_function = lambda x, y: x if y in x else x + [y]
reduce(run_function, [[], ] + data_list)

 

 

reduce函数为Python内置函数:

reduce(function, iterable[, initializer])
将数据集中的第一个和第二个元素通过function(有两个参数)进行运算处理,得到的结果在和第三个元素进行运算,以此类推

run_function 对传入参数进行判断去重
[[], ] + data_list 为可迭代对象

相关文章:

  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案