Project: leaderboard
Python · Unit 10: More on functions
- Full plan
- Python
- Project
- 3 exercises
You'll build the leaderboard for a tournament. Each player is a tuple (name, points).
With -p[1] in the key, whoever has the most points wins. But Leo and Bea tie, and they stay in the order they came in.
table = [
("Leo", 7),
("Ana", 9),
("Bea", 7),
]
order = sorted(
table, key=lambda p: -p[1]
)
print(order)Prints
[('Ana', 9), ('Leo', 7), ('Bea', 7)]The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Fill in the key so whoever has the most points wins, and in a tie, the name that comes first alphabetically.
2. Write the code
Write
standings(table). Each player intableis(name, points). Return the list of names from most to fewest points, and if they tie, in alphabetical order.3. Write the code
Write
leader(table): return the name of whoever is in first place, with the same tie-break. If the table is empty, return"".
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.