By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

I need to sort a Class!

P: 1
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. class TopScore():
  3.   def __init__(self):
  4.     self.Name = "-"
  5.     self.Score = 0
  6.  
  7.  
Basically, it saves high scores for a game. The Name is a string and Score is an integer.
Mar 31 '11 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
The sorting wiki has examples for sorting all types http://wiki.python.org/moin/HowTo/Sorting/
Mar 31 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.