def children(node): """ Gets list of *node*'s children :param node: node in question :return: list of children """ return snd(node)
def remove_from_node(node, child_to_remove): """ Removes the *child_to_remove* from a *node* :param node: node in question :param child_to_remove: child in question :return: tuple with orphans and whether remove occurred """ children_names = list(History.children_names(node)) try: child_to_remove_index = children_names.index(child_to_remove) result = History.children(History.children(node)[child_to_remove_index]), True del History.children(node)[child_to_remove_index] return result except ValueError: children_call_result = [History.remove_from_node(child_node, child_to_remove) for child_node in History.children(node)] return reduce(lambda l, r: l if snd(l) else r, children_call_result, ([], False))