def insert(elem, list): """Return a copy of LIST with ELEM sorted in""" if len(list) == 0: return [elem] head = list[0] tail = list[1:] if elem <= head: return list + [elem] return [head] + insert(elem, tail) def sort(list): """Return a sorted copy of LIST""" if len(list) <= 1: return list head = list[0] tail = list[1:] return insert(head, sort(tail))