i would like to quicksort a list of list which i generatet from a csv via pandas. I want to sort it by a specific column e.g. number oder height.
The Data looks like this:
| Number | Name | Height | Width | Weigth |
|---|---|---|---|---|
| 1 | Hatity | 66.23 | 57.28 | 124.87 |
| 2 | Bamity | 22.56 | 843.7 | 123.67 |
| 3 | Asoka | 45.66 | 234.3 | 523.29 |
I was already able to sort it by the second column with this code:
def quickSort(list):
if not list:
return list
pivot = list[0]
lesser = quickSort([x for x in list[1:] if x[1] < pivot[1]])
greater = quickSort([x for x in list[1:] if x[1] >= pivot[1]])
return lesser + [pivot] + greater
print(quickSort(product_list))
This is working fine for sorting by name. But i dont know what to change to sort by any other column. It would be great if somebody could help me.