2024-05-20 21:28:52 发布
网友
我有一个程序可以生成一个非常大的字典样式列表,如下所示:
{"a":"b", "b":"c", "C":"d", "d":"b", "d":"e"}
我想创建一个程序,使用类似pygame的东西来生成一个流程图,使用箭头将所有的第一个术语连接到最后一个术语。这将忽略重复的连接,并在项目自身加倍时生成循环。在
如果上面的列表被处理,它看起来像这样(请原谅手绘):
当我需要这样做时,我使用了pydot和{a2}
使用Graph Tool:
from graph_tool.all import * g = Graph() vals = [("a","b"), ("b","c"), ("c","d"), ("d","b"), ("c","e")] vertexes_names = g.new_vertex_property("string") vertexes = {} for start, stop in vals: if start not in vertexes: vertexes[start] = g.add_vertex() vertexes_names[vertexes[start]] = start if stop not in vertexes: vertexes[stop] = g.add_vertex() vertexes_names[vertexes[stop]] = stop g.add_edge(vertexes[start], vertexes[stop]) graph_tool.stats.remove_parallel_edges(g) graph_draw(g, vertex_text=vertexes_names, vertex_font_size=18, output="output.png")
当我需要这样做时,我使用了pydot和{a2}
使用Graph Tool:
相关问题 更多 >
编程相关推荐