code: def combine_lists(d, keys=None, deepcopy=True):
        # noqa: E501
      if isinstance(d, list):
          init_list = True
          d = {'dummy_key843': d}
      else:
          init_list = False
  
      flattened = flatten(d, list_of_dicts=None)
      for key, value in list(flattened.items()):
          if keys is not None:
              try:
                  if not key[-1] in keys:
                      continue
              except Exception:
                  continue
          if not isinstance(value, list):
              continue
          if not all([is_dict_like(d) for d in value]):
              continue
          newd = {}
          for subdic in value:
              for subk, subv in subdic.items():
                  if subk not in newd:
                      newd[subk] = []
                  newd[subk].append(subv)
          flattened[key] = newd
  
      final = unflatten(flattened, list_of_dicts=None, deepcopy=deepcopy)
  
      if init_list:
          return list(final.values())[0]
      else:
          return final
docs: combine lists of dicts
  
      Parameters
      ----------
      d : dict or list[dict]
      keys : list
          keys to combine (all if None)
      deepcopy: bool
          deepcopy values
  
      Example
      -------
      >>> from pprint import pprint
      >>> d = {'path_key': {'a': 1, 'split': [{'x': 1, 'y': 3}, {'x': 2, 'y': 4}]}}
      >>> pprint(combine_lists(d,['split']))
      {'path_key': {'a': 1, 'split': {'x': [1, 2], 'y': [3, 4]}}}
  
      >>> combine_lists([{"a":2}, {"a":1}])
      {'a': [2, 1]}