0

So I have a few lines of code that put a users name and score into a file:

hs = open("hst.txt", "a")
hs.write(name + " ")
hs.write(str(score) + "\n")
hs.close()

Without using a function already in python can someone show me how to perform a sort (preferably a simple sort) on this to put it in order from largest numbered score to smallest?

tshepang
  • 12,111
  • 21
  • 91
  • 136
RyanH2796
  • 1,119
  • 2
  • 7
  • 8
  • 1
    If you're doing this for some assignment, here's a good post to learn from: http://stackoverflow.com/questions/895371/bubble-sort-homework – Ryan O'Donnell Feb 18 '14 at 13:26
  • A bubble sort could work but a simple sort would be preferable, do you know where I could find information on that? – RyanH2796 Feb 18 '14 at 13:45
  • I'm not too familiar with simple sorts, just types of sorts that could be classified as simple? Maybe look at insertion sorts implemented in Python? :) – Ryan O'Donnell Feb 18 '14 at 14:05
  • In order to do that, you will first have to read all the scores in the file, sort them and then write them out. – Burhan Khalid Aug 30 '14 at 09:29

0 Answers0