开发者

Convert nested list into tree picture

开发者 https://www.devze.com 2023-04-12 00:57 出处:网络
I have a JSON/Python nested list which represents a tree, each item being a node, if the node is a list, it is a subtree.

I have a JSON/Python nested list which represents a tree, each item being a node, if the node is a list, it is a subtree.

Any easy way to create some pleasing graphics out of that?

[[1, [[4, [[7], [8], [9]]], [5, [[7], [8], [9]]]开发者_高级运维, [6, [[7], [8], [9]]]]], [2, [[4, [[7], [8], [9]]], [5, [[7], [8], [9]]], [6, [[7], [8], [9]]]]], [3, [[4, [[7], [8], [9]]], [5, [[7], [8], [9]]], [6, [[7], [8], [9]]]]]]

This is a neater layout of the JSON itself, which does not help me too much.


You could look into GraphViz for making basic graph images using its simple dot notation. Then in python you could make a really simple recursive function that generates the dot file and builds the graph.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号