middle = len(lst) / 2
left = mergesort(lst[:middle])[0]
right = mergesort(lst[middle:])[0]
sortedlist, splits = merge(left, right)
return sortedlist, splits
Merge sort to count split inversions in Python