Created
September 10, 2021 13:11
-
-
Save fabiommendes/d4498fc126def90cc6ad4bdc13fd72a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DICA: Lembre-se de criar um arquivo leaderboard.txt, | |
| # caso ele não exista! | |
| # Lê arquivo com recordes | |
| with open("leaderboard.txt", "r") as arquivo: | |
| recordes = [] | |
| for linha in arquivo: | |
| nome, _sep, valor = linha.rpartition(':') | |
| recordes.append((nome, int(valor))) | |
| # Novo recorde! | |
| def get_num(t): | |
| return -t[1] | |
| recordes.append(("Church", 19)) | |
| recordes.sort(key=get_num) | |
| # Escreve lista atualizada | |
| with open("leaderboard.txt", "w") as arquivo: | |
| for nome, valor in recordes: | |
| arquivo.write(f'{nome}:{valor}\n') | |
| print(recordes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment