<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def nodes_walker(node, ascendants=False):
 """ Defines a generator used to walk into Nodes hierarchy. Usage:: MyNodeB MyNodeD MyNodeF MyNodeG MyNodeH MyNodeE MyNodeC :param node: Node to walk. :type node: AbstractCompositeNode :param ascendants: Ascendants instead of descendants will be yielded. :type ascendants: bool :return: Node. :rtype: AbstractNode or AbstractCompositeNode """


    attribute = "children" if not ascendants else "parent"
    if not hasattr(node, attribute):
        return

    elements = getattr(node, attribute)
    elements = elements if isinstance(elements, list) else [elements]

    for element in elements:
        yield element

        if not hasattr(element, attribute):
            continue

        if not getattr(element, attribute):
            continue

        for sub_element in nodes_walker(element, ascendants=ascendants):
            yield sub_element