leaderboard in python

Solutions on MaxInterview for leaderboard in python by the best coders in the world

showing results for - "leaderboard in python"
Anthony
21 Mar 2017
1# leaderboard = []
2f = open('Leaderboard.txt', 'r')
3leaderboard = [line.replace('\n','') for line in f.readlines()]
4
5
6for i in leaderboard:
7    print(i)
Dylan
17 Sep 2016
1#append the name and score to the file, in the format:
2#"(name) + (score) + \n"
3f = open("top_scores", "a")
4f.write(player1 + " " + str(player1_score) + "\n")
5f.write(player2 + " " + str(player2_score) + "\n")
6f.close()
7
8#this outputs the name and score from the file in order of highest score to lowest
9file = open('top_scores').readlines()
10scores_tuples = []
11for line in file:
12    name, score = line.split()[0], line.split()[1]
13    scores_tuples.append((name, score))
14scores_tuples.sort(key=lambda t: t[1], reverse=True)
15print("\n\n\tHigh Scores\n")
16for i, (name, score) in enumerate(scores_tuples[:5]):
17    print("Player: {} - Score: {} ".format(name, score))
Mirko
28 Jan 2020
1myList = {"person1": 1, "person2": 1, "person3": 1}
2myList["person2"] += 30
3print(myList)
4# {'person1': 1, 'person2': 31, 'person3': 1}
5