def METHOD_NAME(tree, cases, tree2):
    """helper method for ``build_pruned_tree``"""
    is_results = False
    if isinstance(tree[0], str):
        try:
            name, icase, cases2 = tree
        except ValueError:
            print(tree)
            raise
        if isinstance(icase, int):
            assert cases2 == [], tree
            if icase in cases:
                is_results = True
                tree2.append(tree)
        else:
            assert icase is None, tree
            tree3 = []
            for case in cases2:
                is_resultsi, tree3 = METHOD_NAME(case, cases, tree3)
                if is_resultsi:
                    is_results = True
            if is_results:
                tree2.append((name, icase, tree3))
    else:
        tree3 = []
        for case in tree:
            is_resultsi, tree3 = METHOD_NAME(case, cases, tree3)
            if is_resultsi:
                is_results = True
        tree2 = tree3
    return is_results, tree2