Created
November 8, 2021 15:41
-
-
Save scidam/e646a07cbda7034acdc8c0f5bd02b998 to your computer and use it in GitHub Desktop.
My solution to Medal challenge
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
| from collections import namedtuple | |
| with open('olympics.txt', 'rt', encoding='utf-8') as file: | |
| olympics = file.read() | |
| medal = namedtuple('medal', ['City', 'Edition', 'Sport', 'Discipline', 'Athlete', 'NOC', 'Gender', | |
| 'Event', 'Event_gender', 'Medal']) | |
| medals = [medal(*line.split(';')) for line in olympics.split('\n')[1:] if line] | |
| def get_medals(**kwargs): | |
| '''Return a list of medal namedtuples ''' | |
| result = [] | |
| for medal in medals: | |
| if all(getattr(medal, att, False) == val for att, val in kwargs.items()): | |
| result.append(medal) | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment