I need to sort a Class!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Slade
    New Member
    • Mar 2011
    • 1

    I need to sort a Class!

    I have a class called TopScores which contains two objects score and name. I need to sort them in descending order of score, but dont know how to do it :(

    Here's the code

    Code:
    class TopScore():
      def __init__(self):
        self.Name = "-"
        self.Score = 0
    Basically, it saves high scores for a game. The Name is a string and Score is an integer.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    The sorting wiki has examples for sorting all types http://wiki.python.org/moin/HowTo/Sorting/

    Comment

    Working...