docs: def expand_dict(flat_dict, sep='_'):
      """Expand a flattened dictionary.
  
      :param dict flat_dict: a nested dictionary that has been flattened so the keys are composite
      :param str sep: the separator between concatenated keys
      :rtype: dict
      """
      res = {}
      rdict = defaultdict(list)
  
      for flat_key, value in flat_dict.items():
          key = flat_key.split(sep, 1)
          if 1 == len(key):
              res[key[0]] = value
          else:
              rdict[key[0]].append((key[1:], value))
  
      for k, v in rdict.items():
          res[k] = expand_dict({ik: iv for (ik,), iv in v})
  
      return res