fork(1) download
  1. sampletree = {'spl':'foo', 'go_r':{'cut':150} , 'l':{'val':100}, 'r':{'val':200}}
  2.  
  3. def TREE_PRINT(tree, indent=''):
  4. #is this a leaf node?
  5. if 'val' in tree:
  6. print str(tree['val'])
  7. else:
  8. #print the criteria
  9. print 'split: '+ str(tree['spl']) + ' ' + str(tree['go_r'])
  10. #print the branches
  11. print indent+'L->',
  12. TREE_PRINT(tree['l'], indent+' ')
  13.  
  14. print indent+'R->',
  15. TREE_PRINT(tree['r'], indent+' ')
  16.  
  17. TREE_PRINT(sampletree)
Success #stdin #stdout 0.01s 6356KB
stdin
Standard input is empty
stdout
split: foo {'cut': 150}
L-> 100
R-> 200