python - Keeping name and score together while sorting -


So I need to sort some high scores in order and here is the code I already have:

  def sortscores (): name list = [] scorelist = [] hs = open ("hst.txt", "r") for hscounter = 0 hs in line: if counter% 2 ! = 0: name = line othername = name [0: lena (name) -1] nomilist. Append (alias) other: scorelist.append (int (line))  

And puts the numbers in the list. I have to sort them, but I can not use the .sort () function because I have to type myself so that someone can tell me how do I do this? (Sort the descending order in the order with the correct sequence of the score)

Scores in high (name, digits), you can easily put them together. Since you have to type the sort function manually, it can be helpful to see an example of using tuples in other problems. Here's an example of getting the maximum number of names and scores together.

First of all, set up the data. You can use zip for this

  names = ['John', 'Jane', 'Tim', 'Sarah]] score = [100, 120, 80, 90] data = list (zip (name, score)) for # Python 2.x You do not need the 'list' constructor print (data)  

Output:

  [('John', 100), 'Jane', 120), ('Tim', 80), ('Sarah', 90)]  

Find the maximum entry now:

  Maximum entry for data entry = ('', 0): If the entry [1] & gt; Max_entry [1]: max_entry = Entry Print (max_entry)  

Output:

  ('Jane', 120)  

Comments