title: Type error: unpacking tuples Recursive function call
body: <p>I have the following piece of code:</p>
  <pre><code>def myCalculation(self, root, max_val): 
          
          if root == None:
              return -1
          
          LH = 1 + (self.myCalculation(root.left, max_val))[0]
          RH = 1 + (self.myCalculation(root.right, max_val))[0]
          
          ret = LH+RH
          
          if max_val &lt; ret:
              max_val = ret
              
          return (max(LH, RH), max_val)
  </code></pre>
  <p>Here, I return two values because for the last function call on stack to exit the function must return the max_val to the calling function. So, when at the 3rd and 4th executable lines of the function I make a function call and try to use the return values, it gives TypeError desribed just below.</p>
  <p>The error is :</p>
  <pre><code>&gt; TypeError: 'int' object has no attribute '__getitem__'
  </code></pre>
  <p>Full traceback:</p>
  <pre><code>TypeError: 'int' object has no attribute '__getitem__'
      LH = 1 + (self.myCalculation(root.left, max_val))[0]
  Line 14 in myCalculation (Solution.py)
      LH = 1 + (self.myCalculation(root.left, max_val))[0]
  Line 14 in myCalculation (Solution.py)
      LH, max_val1 = 1 + self.myCalculation(root.left, 0)
  Line 32 in diameterOfBinaryTree (Solution.py)
      ret = Solution().diameterOfBinaryTree(param_1)
  Line 67 in _driver (Solution.py)
  _driver()
  </code></pre>
  <p>Line 77 in  (Solution.py)</p>
  <p>I cannot quite figure what the problem is with packing and unpacking tuples in recursion?</p>