def find_first_common_ancestor(node1, node2):
    """
    Find the first common ancestor for two nodes in the same tree.

    Parameters
    ----------
    node1 : nltk.tree.ParentedTree
        The first node.
    node2 : nltk.tree.ParentedTree
        The second node.

    Returns
    -------
    ancestor_node : nltk.tree.ParentedTree
        The first common ancestor for two nodes in the same tree.
    """
    # make sure we are in the same tree
    assert node1.root() == node2.root()

    # make a set of all ancestors of node1
    node1_ancestor_treepositions = set()
    node1_parent = node1.parent()
    while node1_parent is not None:
        # note: storing treepositions isn't particularly efficient since
        # treeposition() walks up the tree; using memory addresses like
        # id(node1_parent) would be faster, but seems potentially
        # hazardous/confusing
        node1_ancestor_treepositions.add(node1_parent.treeposition())
        node1_parent = node1_parent.parent()

    # find the first ancestor of node2 that is also an ancestor of node1
    node2_parent = node2.parent()
    res = None
    while node2_parent is not None:
        if node2_parent.treeposition() in node1_ancestor_treepositions:
            res = node2_parent
            break
        node2_parent = node2_parent.parent()

    assert res is not None
    return res