joker

This guy was pretty funny.

I'm trying to sort my list to do binary search but it is taking hours to run. I know it works because when the list is small it only took a few seconds, but for my list with 200 elements it's taken over 2 hours. I don't know what's wrong. Can anyone help?

def sort_list(l):

def helper(i, j):
    if i >= j:
        return
    m = (i + j) // 2
    helper(i, m)
    helper(m + 1, j)
    if l[m] > l[j]:
        l[m], l[j] = l[j], l[m]
    helper(i, j - 1)

helper(0, len(l) - 1)

I know python has sort built in but I wanted to try writing my own.


Tags: