def common_parent(terms, go):
    """
    This function finds the common ancestors in the GO
    tree of the list of terms in the input.
    - input:
        - terms: list of GO IDs
        - go: the GO Tree object
    Taken from 'A Gene Ontology Tutorial in Python - Model Solutions to Exercises'
    by Alex Warwick
    """
    # Find candidates from first
    rec = go[terms[0]]
    candidates = rec.get_all_parents()
    candidates.update({terms[0]})

    # Find intersection with second to nth term
    for term in terms[1:]:
        rec = go[term]
        parents = rec.get_all_parents()
        parents.update({term})
        # Find the intersection with the candidates, and update.
        candidates.intersection_update(parents)
    return candidates