def _tree_to_paths(tree):
    """Build a list of paths made by walking from the root of the tree to each leaf."""

    if len(tree) == 0:
        return [""]
    return [
        c + path
        for c, subtree in sorted(tree.items())
        for path in _tree_to_paths(subtree)
    ]