import randomdef qsort(qslist):    small = []    big = []    if (len(qslist) < 2):        return qslist    elif (len(qslist) > 1):        pivot = qslist[int(random.randrange(len(qslist)))]        for x in range(len(qslist)):            if qslist[x] <= pivot:                small.append(qslist[x])            else:                big.append(qslist[x])        if(len(big) == 0):            big.append(pivot)            small.remove(pivot)return qsort(small) + qsort(big)qslist = [9,1,8,2,7,3,6,4,5]print(qsort(qslist))Please give me advice while picking up Python.  I'm trying to do so while at the same time doing some basic algorithms.Have I understood how the quicksort algorithm work?Please give me some general feedback on the Python code.
Is this a proper quicksort algorithm in Python?
python;algorithm;recursion;quick sort
Some comments:Write docstrings to document codeUse if/else instead of if/elif if possibleUse list comprehensionsUse random.choice to get a random element from a non-empty sequenceThe code in the original questions with the suggested improvements would be as follows:import randomdef qsort(qslist):    Quicksort implementation.    if len(qslist) < 2:        return qslist    pivot = random.choice(qslist)    small = [x for x in qslist if x < pivot]    equal = [x for x in qslist if x == pivot]    big = [x for x in qslist if x > pivot]    return qsort(small) + equal + qsort(big)qslist = [9,1,8,2,7,3,6,4,5]print(qsort(qslist))Edit: If you prefer to avoid traversing the array three times, a partitionfunction to do that very similar to the one in the original question would be:def partition(qslist):    Partition array using a pivot value.    small = []    equal = []    big = []    pivot = random.choice(qslist)    for x in qslist:        if x < pivot:            small.append(x)        elif x == pivot:            equal.append(x)        else:            big.append(x)    return small, equal, big