title: LeetCode python recursive solution
body: <p>So I saw this solution in leetcode discussions and I cannot wrap my head around it.</p>
  <pre><code>    # Definition for singly-linked list.
      class ListNode(object):
          def __init__(self, val=0, next=None):
              self.val = val
              self.next = next
  
      class Solution:
          def addTwoNumbers(self, l1, l2):
              def toint(node):
                  a = node.val if node else 0 
                  print(a) #prints 2 4 3
         HERE===&gt; x = node.val + 10 * toint(node.next) if node else 0
                  print(x) #prints 3 4 2
                  return x
              def tolist(n):
                  node = ListNode(n % 10)
                  if n &gt; 9:
                      node.next = tolist(n / 10)
  
                  return node
              return tolist(toint(l1) + toint(l2))
  
          
      a, a.next, a.next.next = ListNode(2), ListNode(4), ListNode(3)
      b, b.next, b.next.next = ListNode(5), ListNode(6), ListNode(4)
      result = Solution().addTwoNumbers(a, b)
      print(&quot;{0}, {1}, {2}&quot;.format(result.val, result.next.val, result.next.next.val))
  </code></pre>
  <p>What I don't understand is how does it take a number, add 10 and multiply by next and finally reverse them.</p>
  <p>Can someone explain the line I marked HERE===&gt;</p>