def merge(a, b):
    if len(a) * len(b) == 0:
        return a + b

    v = (a[0] < b[0] and a or b).pop(0)
    return [v] + merge(a, b)


def mergesort(list):
    if len(list) < 2:
        return list

    m = len(list) / 2
    return merge(mergesort(list[:int(m)]), mergesort(list[int(m):]))

@@ -1,20 +1,609 @@
-def merge(a, b):
+%22%22%22 Merge Sort%0AThe Merge Sort is a recursive sort of order n*log(n).%0A%0AIt is notable for having a worst case and average complexity of O(n*log(n)),%0Aand a best case complexity of O(n) (for pre-sorted input).%0A%0AThe basic idea is to split the collection into smaller groups by halving it%0Auntil the groups only have one element or no elements (which are both entirely%0Asorted groups).Then merge the groups back together so that their elements are%0Ain order.%0A%0AThis is how the algorithm gets its %22divide and conquer%22 description.%0A%22%22%22%0A%0A%0Adef merge(left, right):%0A    %22%22%22Merge two list keeping the elements in order.%22%22%22
 %0A   
@@ -614,17 +614,20 @@
 len(
-a
+left
 ) * len(
 b) =
@@ -622,17 +622,21 @@
 ) * len(
-b
+right
 ) == 0:%0A
@@ -654,40 +654,63 @@
 urn 
-a + b%0A%0A    v = (a
+left + right%0A%0A    merge_list = (left
 %5B0%5D %3C 
-b
+right
 %5B0%5D and 
 a or
@@ -709,14 +709,21 @@
 and 
-a or b
+left or right
 ).po
@@ -743,23 +743,39 @@
 rn %5B
-v%5D + merge(a, b
+merge_list%5D + merge(left, right
 )%0A%0A%0A
@@ -784,24 +784,33 @@
 f mergesort(
+unsorted_
 list):%0A    i
@@ -808,23 +808,63 @@
 t):%0A    
-if len(
+%22%22%22Merge Sort function.%22%22%22%0A    if len(unsorted_
 list) %3C 
@@ -881,16 +881,25 @@
  return 
+unsorted_
 list%0A%0A  
@@ -905,15 +905,26 @@
    m
+id
  = len(
+unsorted_
 list
@@ -937,21 +937,20 @@
     
-return merge(
+left_part = 
 merg
@@ -951,24 +951,33 @@
 = mergesort(
+unsorted_
 list%5B:int(m)
@@ -979,12 +979,30 @@
 nt(m
+id
 )%5D)
-,
+%0A    right_part =
  mer
@@ -1008,16 +1008,25 @@
 rgesort(
+unsorted_
 list%5Bint
@@ -1031,10 +1031,51 @@
 nt(m
+id
 ):%5D)
+%0A    return merge(left_part, right_part
 )%0A

Add documentation