fork download
  1. d=lambda t:t>{}and-~max(map(d,t+[0]))
  2. s=lambda x,y:s(y,x)if d(y)<d(x)else map(s,(x,[x]*len(y))[d(x)<d(y)],y)if d(y)else(x or 0)+(y or 0)
  3.  
  4. for (x, y) in (
  5. (0, 0),
  6. ([-1, 0, -1], [1]),
  7. ([], [0]),
  8. ([], 0),
  9. ([], []),
  10. ([[], 0], []),
  11. ([1, 2, 3], 10),
  12. ([1, 2, 3], [10]),
  13. ([1, 2, 3], [10, [20]]),
  14. ([1, 2, 3, []], [10, [20]]),
  15. ([1, [2, [3, [4]]]], [10, [20]])
  16. ):
  17. print s(x, y)
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
0
[0, 0, -1]
[0]
[]
[]
[[], []]
[11, 12, 13]
[11, 2, 3]
[[11, 12, 13], [21, 2, 3]]
[11, [22], 3, []]
[[11, [21]], [[12, [22]], [13, [24]]]]