title: sorting lists in python using merge sort
body: <p>I have here a code for sorting lists using merge sort.. I just got it somewhere in the net.. But honestly, I can't follow the flow of the code... I mean, I can't get how it is implemented. I can understand some part especially the first one where it divides the entire list in two and then sort each side of the list. And then what?? Will you please tell what's happening here? Thank you. :)  </p>
  
  <pre><code>def merge(badlist):
      if len(badlist) == 1:  
      return badlist  
      m = len(badlist)/2  
      l = merge(badlist[:m])  
      r = merge(badlist[m:])  
      if not len(l) or not len(r):  
          return l or r  
      result = []  
      i = j = 0  
      while (len(result) &lt; len(r) + len(l)):  
          if l[i] &lt; r[j]:  
              result.append(l[i])  
              i += 1  
          else:  
              result.append(r[j])  
              j += 1  
          if i == len(l) or j == len(r):  
              result.extend(l[i:] or r[j:]) 
              break  
      return result  
  print merge(badlist)  
  </code></pre>