fork download
  1. import random
  2. L = [random.randrange(20) for x in range(20)]
  3. print "Unsorted:", L
  4.  
  5. def sort(L):
  6. # terminal case first. Otherwise sort each half recursively and combine
  7. return L.sort() if L > 1 else sort(L[:len(L)//2]) + sort(L[len(L)//2:])
  8.  
  9. sort(L)
  10. print "Sorted:", L
  11.  
  12.  
Success #stdin #stdout 0.02s 10328KB
stdin
Standard input is empty
stdout
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]