Skip to content

Instantly share code, notes, and snippets.

@calroc
Created January 4, 2013 05:52
Show Gist options
  • Save calroc/4450250 to your computer and use it in GitHub Desktop.
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
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