title: A recursive function to sort a list of ints
body: <p>I want to define a recursive function can sort any list of ints:</p>
  
  <pre><code>def sort_l(l):
      if l==[]:
          return []
      else:
          if len(l)==1:
              return [l[-1]]
          elif l[0]&lt;l[1]:
              return [l[0]]+sort_l(l[1:])
          else:
              return sort_l(l[1:])+[l[0]]
  </code></pre>
  
  <p>Calling this function on a list [3, 1, 2,4,7,5,6,9,8] should give me:</p>
  
  <pre><code>[1,2,3,4,5,6,7,8,9]
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>print(sort_l([3, 1, 2,4,7,5,6,9,8]))--&gt; [1, 2, 4, 5, 6, 8, 9, 7, 3]
  </code></pre>
  
  <p>Please help me to fix the problem, actual code would be appreciated. Thanks!</p>