Hi Marc, a first observation: stack.get(0) returns but does NOT remove the first element from a list (even if you name it stack). If you want a stack, you need to use the pop method.
See also here: https://docs.python.org/3/tutorial/datastructures.html#using-lists-as-stacks Best regards Christian marc nicole <mk1853...@gmail.com> schrieb am Di., 9. Jan. 2024, 18:37: > I want to extract the subtree from the RegressionTree resulting from > training the associated model based on inputs: rootNode and depth, > > Here's my buggy code (that I want it to be checked for errors) > > def extract_tree_depth_first_traversal(tree, root_start, t_depth): > depth = 1 > sub_tree = [] > stack = Queue() > stack.put(root_start) > while stack: > current_node = stack.get(0) > sub_tree.append(current_node) > left_child = tree.children_left[current_node] > if left_child >= 0: > stack.put(left_child) > right_child = tree.children_right[current_node] > if right_child >= 0: > stack.put(right_child) > children_current_node = [left_child, right_child] > for child in children_current_node: > sub_tree.append(child) > if depth >= t_depth: > break > depth = depth + 1 > return sub_tree > > Could somebody spot the error for me ? > > _______________________________________________ > scikit-learn mailing list > scikit-learn@python.org > https://mail.python.org/mailman/listinfo/scikit-learn >
_______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn