def lca(nodes):
    """Returns the Least Common Ancestor (LCA) of a list of nodes"""

    if len(nodes) == 1:
        return nodes[0]
    elif len(nodes) > 2:
        return lca([lca(nodes[:2])] + nodes[2:])
    elif len(nodes) == 2:
        node1, node2 = nodes
        set1 = set([node1])
        set2 = set([node2])

        while True:
            if node1 in set2:
                return node1
            if node2 in set1:
                return node2
            if node1.parent is not None:
                node1 = node1.parent
            if node2.parent is not None:
                node2 = node2.parent

            set1.add(node1)
            set2.add(node2)
    else:
        raise Exception("No nodes given")