def subdivide(G, pendant):
    """
    Given a graph with a list of pendant nodes (and their edges),
    subdivides each of the pendant edges.

    INPUT
    G: A networkx graph
    pendant: A list of the form [[vertex, edge] ...] where
    vertex is pendant and edge is the only edge incident to
    vertex

    OUTPUT
    Gh: The subdivision of G
    """
    Gh = G.copy()
    for pendantEdge in pendant:
        vertex = pendantEdge[0]
        edge = pendantEdge[1]
        Gh.remove_edge(*edge)
        Gh.add_node(str(edge))
        Gh.add_edge(edge[0], str(edge))
        Gh.add_edge(edge[1], str(edge))
    return Gh
