so i have a project due in my computer programming class and i need some serious help. we are learning about recursive sorting, such as merge sort, selection sort, etc.

my project has to do with taking 10 people and sorting them in order by their names (alpabetically), rank (numerically), country (alphabetically), and the amount of games they have played (numerically).

so far, this is my code.
class Players:

def __init__(self, name, rank, tournamentsPlayed, country):
self.name = name
self.rank = rank
self.tournamentsPlayed = tournamentsPlayed
self.country = country

def __repr__(self):
return repr((self.name, self.rank, self.tournamentsPlayed, self.country))

def __init__(self):
self.Players = []
self.Players.append = ("Roger Federer", 1, 18, "SUI")
self.Players.append = ("Novak Djokovic", 2, 21, "SRB"),
self.Players.append = ("Rafael Nadal", 3, 17, "ESP"),
self.Players.append = ("Juan Martin Del Potro", 4, 18, "ARG"),
self.Players.append = ("Andy Murray", 5, 17, "GBR"),
self.Players.append = ("Nikolay Davydenko", 6, 25, "RUS"),
self.Players.append = ("Robin Soderling", 7, 25, "SWE"),
self.Players.append = ("Andy Roddick", 8, 20, "USA"),
self.Players.append = ("Fernando Verdasco", 9, 26, "ESP"),
self.Players.append = ("Jo-Wilfried Tsonga", 10, 25, "FRA")

i know it still needs a lot of work. any help would be much appreciated. thanks in advance.

(code) button must be used to paste program in understandable and original form. So you are not allowed to use built in sort or what? You did not give explanation of your title nor what is your request.
Also why you are redefining the __init__ instead of using object defined?

For starters, why don't you simplify your data set so it is just one thing (name string, maybe), and write a recursive sort that handles that one thing. Once you have the sort working, you can extend it a little bit to pick out a particular field from the data and sort on that field.

If I were the teacher, I'd be looking for:
- Do you understand how recursion works
- Is your code modular (can you plug in a different sort method?)
- Is your code clean and well commented
... and if I were doing this one, I'd handle it by having a class Player, a file reader to get the data for a bunch of Player instances and put them in a list (or I'd make a python file that created the list and import it). I'd have one or more sort functions that handle a list of Player, and a driver function that displayed the initial list, called the sort function, and displayed the sorted list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.