from collections import defaultdict

def combine_values(*dicts):
  res = defaultdict(list)
  for d in dicts:
    for key in d:
      res[key].append(d[key])
  return dict(res)
d1 = {'a': 1, 'b': 'foo', 'c': 400}
d2 = {'a': 3, 'b': 200, 'd': 400}

combine_values(d1, d2) # {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]}

 

相关文章:

  • 2021-09-15
  • 2021-12-26
  • 2022-12-23
  • 2022-03-04
  • 2021-10-20
猜你喜欢
  • 2021-10-24
  • 2022-12-23
  • 2021-07-15
  • 2022-03-03
  • 2021-08-01
  • 2022-12-23
  • 2021-09-18
相关资源
相似解决方案