473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 1528
dwblas
626 Expert 512MB
The sorting wiki has examples for sorting all types http://wiki.python.org/moin/HowTo/Sorting/
Mar 31 '11 #2

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

Similar topics

2
by: Jim | last post by:
Hi, Does anyone know of an available java class that will encrypt to cipher text consisting of only printable ascii characters? One of the things I need it for is to encrypt strings that will...
4
by: DancnDude | last post by:
I have a class that needs to have several different kinds of sorting routines on an ArrayList that it needs to conditionally do based upon the data. I have successfully created a class that...
1
by: Dave Johnson | last post by:
I had a problem in my OO Design, the idea is that i have a DataRepository Class That i want to only inherit from it speacial methods accourding to the child class, like i want the Client Class to...
8
by: Brett Romero | last post by:
I have this situation: myEXE <needs< DerivedClass <which needs< BaseClass Meaning, myEXE is using a type defined in DerivedClass, which inherits from BaseClass. I include a reference to...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
4
by: M Harvey | last post by:
I have an arraylist that contains datetime values. What is the best way to sort this arraylist by date ascending? Thanks, Matt
5
by: akameswaran | last post by:
Disclaimer - I recognize this is not a practical exercise. There are many implementations around that would do the job better, more efficiently (Meaning in C) or whatever. I caught some thread...
10
by: Wing Siu | last post by:
Dear All I would like to develop a generic class sorting function. Currently, when I need sort a collection of user class, for example: Person, Exhibition, Country I need implement a comparer...
3
by: Peter Olcott | last post by:
How does not specify the sort criteria for Generic.List ?? The way that this is done in C++ STL is to implement operator<(), how is this done in C# and DotNet for Generic.List ???
1
by: Marlissa Dijkman | last post by:
I want to use pop3 from PEAR. And now I need a class PEAR. Has somebody got it for me?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.