Reputation: 21
Hi I'm working on a mini game that store user's time taken to complete the game as their score. I'm able to append the scores into my text file but I failed to sort them.
example: 17.25 jason 18.5 simon 20.12 ben
def scoring():
#appending level 1 score
L1=[]
L1.append((Timetaken,myname))
with open('L1.txt','a') as x:
x.write('%f,%s'%(Timetaken,myname))
def arranging():
#Sorting level 1
column=[]
with open('L1.txt') as file1:
for line in file1:
column.append(line.split('\n'))
sorted(column,key=itemgetter(0),reverse=False)
with open("L1.txt",'w+') as first:
for x in column:
if (len(column))<=10:
first.write(str(x)+str(' , '))`
Upvotes: 0
Views: 70
Reputation: 5155
Your issue is that sorted() doesn't sort in place. You need to do:
column = sorted(column,key=itemgetter(0),reverse=False)
Upvotes: 1