I am using quick sort to put my list in order. The list is full of numbers formatted as such:
1999.03,0.9
2000.08,0.1
1988.1,0.8
the number before the decimal point is a year and the number after the decimal point is the month. The number after the comma is a price. My quick sort puts them in order, however it drops the price after I do it and I do not know why. I am new to python so I may not be doing this the best way, but I'd still like someone to show me why this doesnt work
def quick_sort(arr):
if arr == []:
return []
else:
element = arr[len(arr)/2]
pivot = float(element[0:7])
lesser = quick_sort([x for x in arr[1:] if float(x[0:7]) < pivot])
greater = quick_sort([x for x in arr[1:] if float(x[0:7]) >= pivot])
return lesser + [pivot] + greater
The output looks like:
1988.1
1999.03
2000.08
I assume its the syntax in the recursive call of quicksort, however I do not know enough about python to spot it.