I have a text file containing the following data.
ascon1 201707011 John 77.5 11.5 11.5 11.5
ascon1 201707012 Grld 70.0 11.5 11.5 11.5
ascon1 201707013 Josh 79.5 11.5 11.5 11.5
ascon1 201707014 Jess 67.5 11.5 11.5 11.5
ascon1 201707015 Jack 97.5 11.5 11.5 11.5
I need the data to look like this.
ascon1 201707015 Jack 97.5 11.5 11.5 11.5
ascon1 201707013 Josh 79.5 11.5 11.5 11.5
ascon1 201707011 John 77.5 11.5 11.5 11.5
ascon1 201707012 Grld 70.0 11.5 11.5 11.5
ascon1 201707014 Jess 67.5 11.5 11.5 11.5
so here is my code. The above part is working using the inbuilt sorted function from python. but in ascending order instead of decending order.
with open('input.txt') as f:
lines = [line.split(' ') for line in f]
output = open("input(sorted).txt", 'w')
for line in sorted(lines, key=itemgetter(3)):
output.write(' '.join(line))
output.close()
I want to use the quick-sort function to solve this problem. this is my function.
def qsort(d_val):
if len(d_val) <= 1: return d_val
return qsort([lt for lt in d_val[1:] if lt < d_val[0]]) + d_val[0:1] + \
qsort([ge for ge in d_val[1:] if ge >= d_val[0]])