fork download
  1. root = {}
  2. root['a'] = {'b':2, 'c':2}
  3. root['b'] = {'goal': 3}
  4. root['c'] = {'d':1}
  5. root['d'] = {'goal':1}
  6.  
  7.  
  8. # a - b -goal
  9. # 0 2 3 sum 5
  10. # a - c - d goal
  11. # 0 2 1 1 sum 4
  12.  
  13. for k1, v1 in root['a'].items():
  14. l1 = 0 + v1
  15. for k2, v2 in root[k1].items():
  16. l2 = l1 + v2
  17. if 'goal' == k2:
  18. print("{} - {} - {} ({})".format('a', k1,k2, l2))
  19. break
  20. for k3, v3 in root[k2].items():
  21. l3 = l2 + v3
  22. print("{} - {} - {} - {} ({})".format('a', k1,k2,k3, l3))
  23.  
Success #stdin #stdout 0.15s 10264KB
stdin
Standard input is empty
stdout
a - c - d - goal (4)
a - b - goal (5)