title: python recursive pascal triangle
body: <p>After completing an assignment to create pascal's triangle using an iterative function, I have attempted to recreate it using a recursive function. I have gotten to the point where I can get it to produce the individual row corresponding to the number passed in as an argument. But several attempts to have it produce the entire triangle up to and including that row have failed. I even tried writing a separate function which iterates over the range of the input number and calls the recursive function with the iterated digit while appending the individual lines to list before returning that list. The desired output should be a list of lists where each internal list contains one row of the triangle. Like so:</p>
  
  <pre><code>[[1], [1, 1], [1, 2, 1]...]
  </code></pre>
  
  <p>Instead it returns a jumbled mess of a nested list completely filled with 1's.</p>
  
  <p>Here is the recursive function in question, without the second function to append the rows (I really wanted 1 all inclusive function anyway):</p>
  
  <pre><code>def triangle(n):
      if n == 0:
          return []
      elif n == 1:
          return [1]
      else:
          new_row = [1]
          last_row = triangle(n-1)
          for i in range(len(last_row)-1):
              new_row.append(last_row[i] + last_row[i+1])
          new_row += [1]
      return new_row
  </code></pre>
  
  <p>To be clear, I have already completed the assigned task, this is just to provide a deeper understanding of recursion...</p>
  
  <p>Iterative solution:</p>
  
  <pre><code>def triangle(n):
      result = []
      for row in range(n):
          newrow = [1]
          for col in range(1, row+1):
              newcell = newrow[col-1] * float(row+1-col)/col
              newrow.append(int(newcell))
          result.append(newrow)
      return result
  </code></pre>