Sort highscores in file python programming -
i have game programming, highest score saved down onto file in shall sorted after best score etc. have coded class , way save down score, cannot figure out how sort them after eachother like: ex:
16 9 3
the final score process!
# display final score. drawboard(mainboard) scores = getscoreofboard(mainboard)
change
def save_highscore(self, highscore): highscores = set(self.get_highscores(false)) if highscore in highscores: return highscores.add(highscore) open(self.highscore_file, "w") f: f.write(" ".join(str(score) score in highscores))
to
def save_highscore(self, highscore): highscores = set(self.get_highscores(false)) if highscore in highscores: return highscores.add(highscore) open(self.highscore_file, "w") f: f.write("\n".join(str(score) score in sorted(highscores, reverse=true)))
Comments
Post a Comment