Q:

Runtime error, sorting function without using .sort

I am supposed to write the sorting function. Define
a function sort list that takes in a list and returns a list sorted in ascending order.
(4 marks)
Note: your code should make use of the insert list function defined earlier.
With my previous defined variables:
def search(x , seq):
    for i in seq:
        if x > max(seq):
            return len(seq)
        elif x < min(seq):
            return 0
    return search(x, seq[:-1])

def insert_tup(x, tup):
    searchtuple = search(x, tup)
    ontheleft = tup[:searchtuple]
    ontheright = tup[ searchtuple:]
    altogether = ontheleft + (x,) + ontheright
    return altogether

def insert_list(x, lst):
    A = search(x, lst)
    lst.insert(A, x)
return lst

I did a trial
def sort_list(lst):
    result = []
    for i in lst:
        result += [i]
    return insert_list(result[0], lst)

But i keep getting Runtime error where
    File "", line 7, in search
    return search(x, seq[:-1])
The output is desired to be 
sort_list([5, 1, 9]) 
[1, 5, 9]

A:

You are recursively calling the search() method and never breaking out of this loop. I expect this is raising a RuntimeError: maximum recursion depth exceeded exception. 
Python has a recursion limit to protect against infinite recursion. FYI you can modify the recursion limit via sys.setrecursionlimit - but this is not something you should be doing.
Instead you can fix this by re-writing your algorithm iteratively. 
I also suggest you read the Python sorting wiki, as this demonstrates the pythonic way to sort things with the built in sorted() function and the list method sort(). You don't need to re-invent the wheel. 

