import random L = [random.randrange(20) for x in range(20)] print "Unsorted:", L def sort(L): # terminal case first. Otherwise sort each half recursively and combine return L.sort() if L > 1 else sort(L[:len(L)//2]) + sort(L[len(L)//2:]) sort(L) print "Sorted:", L
Standard input is empty
Unsorted: [7, 0, 2, 16, 16, 17, 3, 1, 0, 7, 3, 5, 17, 6, 4, 18, 19, 0, 13, 11] Sorted: [0, 0, 0, 1, 2, 3, 3, 4, 5, 6, 7, 7, 11, 13, 16, 16, 17, 17, 18, 19]