def qsort(tpl, colnum, reverse=False):
small = []
same = []
large = []
if len(tpl) > 1:
pivot = tpl[0][colnum]
if reverse:
for x in tpl:
if x[colnum] > pivot:
small.append(x)
elif x[colnum] == pivot:
same.append(x)
elif x[colnum] < pivot:
large.append(x)
else:
if x[colnum] < pivot:
elif x[colnum] > pivot:
return qsort(small, colnum, reverse) + same + qsort(large, colnum, reverse)
return tpl