Create graph from a list of nodes

Hi
I am trying to create a graph from a list of nodes. my list of nodes was
like this [(John, Harold),(Root, Shaw),(Control,decima)]. i tried
add_edge_list(edges) but it only takes a list of int tuples. is there any
way around it?

attachment.html (431 Bytes)

In graph-tool, vertices are always indexed by integers. So in your case,
you need first to create a mapping of the strings to integers, and then
use that.

    names = ["John", "Harold", "Root", "Shaw", "Control", "decima"]
    idxs = dict(zip(names, range(len(names))))

    edges = [("John", "Harold"),("Root", "Shaw"),("Control","decima")]
    iedges = [(idxs[e[0]], idxs[e[1]]) for e in edges]

    g = Graph()
    g.add_edge_list(iedges)

    # you may want to add the names to a property map for later lookup

    vname = g.new_vertex_property("string")
    for v in g.vertices():
        vname[v] = names[int(v)]

Best,
Tiago