0

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(' , '))`
3
  • 3
    You will get more and better answers if you create a Minimal, Complete, and Verifiable example. Especially make sure that the input and expected test data are complete (not pseudo-data), and can be easily cut and and paste into an editor to allow testing proposed solutions. Commented Jun 13, 2018 at 2:58
  • 1
    what is Timetaken? please show an stackoverflow.com/help/mcve Commented Jun 13, 2018 at 2:58
  • Timetaken is the score of the player Commented Jun 13, 2018 at 3:17

1 Answer 1

1

Your issue is that sorted() doesn't sort in place. You need to do:

column = sorted(column,key=itemgetter(0),reverse=False)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.