def merge_vertices(graph, vertices):
    """
    Merges list of vertices of networkx graph and throws together all
    edges of all the merged vertices.
    """
    v = tuple(vertices)
    graph.add_node(v)
    for i in range(len(v)):
        edgelist = list(graph.edges(v[i]))
        for j in range(len(edgelist)):
            graph.add_edge(v, edgelist[j][0])
            graph.add_edge(v, edgelist[j][1])
        graph.remove_node(v[i])
    return
