简体   繁体   中英

How do I return the values in descending order for the following quick sort code i wrote in python?

this is the code i have currently written for my quick sort algorithm. I want to return it in descending order

这是我目前为我的快速排序算法编写的代码。我想按降序返回

I tweaked the your code and attached it below:

def quicksort(lst, column, descending=True):
    low = []
    high = []
    result = []

    if len(lst) <= 1:
        return lst

    if descending == True:
        pivot = lst[0][column]

        for i in lst:
            if i[column] == pivot:
                result.append(i)
            elif i[column] > pivot:
                low.append(i)
            elif i[column] < pivot:
                high.append(i)

        return quicksort(low, column) + result + quicksort(high, column)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM