human
Complete this python program:
def lexicographical_topological_sort(G, key=None):
assistant
#Here is the Python code you requested.

    """Return a generator of nodes in lexicographically topologically sorted
    order.
    A topological sort is a nonunique permutation of the nodes such that an
    edge from u to v implies that u appears before v in the topological sort
    order.
    Parameters
    G : NetworkX digraph
    A directed acyclic graph (DAG)
    key : function, optional
    This function maps nodes to keys with which to resolve ambiguities in
    the sort order.  Defaults to the identity function.
    Returns
    iterable
    An iterable of node names in lexicographical topological sort order.
    Raises
    NetworkXError
    Topological sort is defined for directed graphs only. If the graph `G`
    is undirected, a :exc:`NetworkXError` is raised.
    NetworkXUnfeasible
    If `G` is not a directed acyclic graph (DAG) no topological sort exists
    and a :exc:`NetworkXUnfeasible` exception is raised.  This can also be
    raised if `G` is changed while the returned iterator is being processed.
    RuntimeError
    If `G` is changed while the returned iterator is being processed.
    Notes
    This algorithm is based on a description and proof in
    "Introduction to Algorithms: A Creative Approach" [1]_ .
    See also
    topological_sort
    References
    .. [1] Manber, U. (1989). "Introduction to Algorithms: A Creative Approach."
    Addison-Wesley.
    """
    if (not G.is_directed()):
        raise nx.NetworkXError('Topological    sort    not    defined    on    undirected    graphs.')
    if (key is None):
        key = (lambda x: x)
    def create_tuple(node):
        return (key(node), node)
    indegree_map = {v: d for (v, d) in G.in_degree() if (d > 0)}
    zero_indegree = [create_tuple(v) for (v, d) in G.in_degree() if (d == 0)]
    heapq.heapify(zero_indegree)
    while zero_indegree:
        (_, node) = heapq.heappop(zero_indegree)
        if (node not in G):
            raise RuntimeError('Graph    changed    during    iteration')
        for (_, child) in G.edges(node):
            try:
                indegree_map[child] -= 1
            except KeyError:
                raise RuntimeError('Graph    changed    during    iteration')
            if (indegree_map[child] == 0):
                heapq.heappush(zero_indegree, create_tuple(child))
                del indegree_map[child]
        (yield node)
    if indegree_map:
        raise nx.NetworkXUnfeasible('Graph    contains    a    cycle    or    graph    changed    during    iteration')