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.