Created
December 14, 2017 08:27
-
-
Save sidharthkuruvila/f59b38215316c0cf6f7d18d21347e504 to your computer and use it in GitHub Desktop.
Generate a graphviz dot file for a digraph represented as an adjacency list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
G = [("A", "B"), ("B", "C"), ("C", "D")] | |
def render_digraph(G): | |
def g(): | |
for p, c in G: | |
yield '"{}" -> "{}"'.format(p, c) | |
lines = "\n".join(g()) | |
return """ | |
digraph {{ | |
{} | |
}} | |
""".format(lines) | |
with file("graph.dot", "w") as fo: | |
fo.write(render_digraph(G)) |
Author
sidharthkuruvila
commented
Dec 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment