title: Recursive functions and lists appending/extending
body: <p>This is a very simple code in place of a bigger problem, but I'm hoping I can tackle it in chunks. I'll start with my first problem. </p>
  
  <pre><code>def testrecurse(z,target):
      x=[]
      if z&lt;target:
          z*=2
          x.append(z)
          x.extend(testrecurse(z,target))
      return x
  </code></pre>
  
  <p>This is a test function to help my brain out with recursion. It takes a number, then shows all the multiplications of two until it hits the target number. so if I enter:</p>
  
  <pre><code>testrecurse(1,1000)
  </code></pre>
  
  <p>I receive:</p>
  
  <pre><code>[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
  </code></pre>
  
  <p>which is great! Output looks good and clean. But here's my problem, I'm having a hard time appending or adding that very first value, in my output. Here's what I want the output to look like.</p>
  
  <pre><code>[1,2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
  </code></pre>
  
  <p>I've tried changing </p>
  
  <pre><code>x=[] to x=[z]
  </code></pre>
  
  <p>but then I receive:</p>
  
  <pre><code>[1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024]
  </code></pre>
  
  <p>any help would be appreciated, I'm new to recursion and it makes my head hurt.</p>