def _get_nodes(x, prefix=""):
    """
    Args:
        x: a tree where internal nodes are dictionaries, and leaves are lists.
        prefix: not meant to be passed. The parent prefix of a label. e.g. given A -> B -> C,
            the parent prefix of C is 'A [sep] B'.
        sep: the separator to use between labels. Could be 'and', '-', or whatever
    Returns:
        All nodes in the hierarchy. Each node is given by a string A [sep] B [sep] C etc.
    """
    res = []
    q = [(x, prefix)]
    while q:
        x, prefix = q.pop()
        if isinstance(x, list):
            res.extend([prefix + k for k in x])
        else:
            for k, v in x.items():
                res.append(prefix + k)
                q.append((v, prefix + k + " - "))
    return list(set(res))