title: Inorder Traversal of Tree in Python Returning a List
body: <p>I learnt implementing inorder traversal of a binary search tree:</p>
  
  <pre><code>def inorder(root): # root has val, left and right fields
      if root==None:
          return
  
      inorder(root.left)
      print(root.val)
      inorder(root.right)
  </code></pre>
  
  <p>Now, the problem is I do not want console output. I want to get the values in a list. I can't find a way to make the function return a list.</p>
  
  <p>I tried <code>s = [inorder(root)]</code> but it doesn't work.</p>
  
  <p>So, my question is:</p>
  
  <ol>
  <li><p>Any way this could be done inside the inorder function, i.e. it should return a list rather than just print values.</p></li>
  <li><p>Is there some generic way to make recusive functions return data structures instead of just outputting a print to console?</p></li>
  </ol>