Search code examples
pythonlistpydot

Pydot - store nodes in list - unhashable type: 'list' error


I'm using pydot to generate a graph from a list of strings

graph = pydot.Dot(graph_type='digraph')
node_list = []
for i in xrange(0, len(string_list)):
    node_list.append(pydot.Node(string_list[i]))
    graph.add_node(node_list[-1])
    for j in (0,len(string_list)):
        graph.add_edge(pydot.Edge(node_list[i], node_list[j], label=matrix[i,j]))

but I get the following error in the add_node line:

TypeError: unhashable type: 'list'

How can I solve this?


Solution

  • You have a list in string_list, the error can be reproduced with:

    graph = pydot.Dot(graph_type='digraph')
    
    node_a = pydot.Node(["Node A"])
    
    graph.add_node(node_a)