Sorting Helper Functions

def swap(lst, a, b):
    lst[a], lst[b] = lst[b], lst[a]

def test(func):
    #a=[786,54,87,543,43,453,65,87,43,312,54,76,6745,543,432,654,76,654,453,32,1,3,6,6,8,9,67,56,5,4,3,4,6,0,7,8,9,90,87,6,4]
    a=[]
    for x in range(random.randrange(34,62)):
        a.append(random.randrange(-25,25))
    testlst(func,a)
    testlst(func,[1,2,3,4,5])
    testlst(func,[5,4,3,2,1])
    testlst(func,[1])
    testlst(func,[])

def testlst(func, lst):
    a=lst
    print a
    b=a[:]
    func(b)
    print b
    c=a[:]
    c.sort()
    print c
    if b==c:
        print "Correct!"
    else:
        print "INCORRECT"
Advertisements