Created
January 4, 2013 05:52
-
-
Save calroc/4450250 to your computer and use it in GitHub Desktop.
A wee little script to convert the Pigeon User Interface into JSON suitable for graphing with the D3.js visualization kit. See http://thinkpigeon.blogspot.com/2013/01/persistant-binary-tree.html
This file contains hidden or 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
from pigeon.xerblin.world import ROOT | |
def trreee(node): | |
key, value, lower, higher = node | |
it = {'name': key} | |
children = [] | |
if lower: | |
children.append(trreee(lower)) | |
if higher: | |
children.append(trreee(higher)) | |
if children: | |
it['children'] = children | |
return it | |
json.dump(trreee(ROOT[1]), open('tree.json','w'), indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment