def GetAllDictPaths(tree_dict):
  """Obtain list of paths to all leaves in dictionary.

  The last item in each list entry is the value at the leaf. For items in
  dictionary that are a list of dictionaries, each list entry is indexed by a
  string repesenting its position in the list.
  Implementation inspired by https://stackoverflow.com/a/40555856.

  Args:
    tree_dict: Input dictionary.

  Returns:
    List of lists with all paths to leaf items in dictionary.

  Example:

  >> a = {'a':[1 , 2, 3],
          'b':[{'c': 10},
               {'d': 20}]
          }

  >> print get_all_dict_paths(a)

    [['a', [1, 2, 3]],
     ['b', '0', 'c', 10],
     ['b', '1', 'd', 20]]
  """
  if isinstance(tree_dict, list):
    if isinstance(tree_dict[0], dict):
      return [[str(i)] + path
              for i, value in enumerate(tree_dict)
              for path in GetAllDictPaths(value)]
    else:
      return [[tree_dict]]
  elif not isinstance(tree_dict, dict):
    return [[tree_dict]]
  return [[key] + path
          for key, value in tree_dict.items()
          for path in GetAllDictPaths(value)]