Goals¶
We want to know which players have scored in the football leage given the results of the matches. To that purpose we have the following two dictionaries.
Firstly, we have a dictionnary with information about the players for each team. Specifically, the key is the name of the team (str) and the value is a list with the names (str) of all the players in that team.
- Secondly, we have a dictionnary with the results of the matches in the following form:
For example:
>>> Dplayers = { ... 'Girona': ['Gazzaniga', 'Bernardo', 'Miguel', 'Arnau', 'David_Lopez', ... 'Valery', 'Juanpe', 'Blind', 'Yan_Couto', 'Eric', 'Kebe', 'Aleix_Garcia', ... 'Pablo_Torre', 'Herrera', 'Ivan_Martin', 'Stuani', ... 'Tsygankov', 'Dovbyk', 'Sabio', 'Portu'], ... 'Almeria': ['Baptistao', 'Mafeo', 'Mario_Garcia'], ... 'Barça': ['ter_Stegen', 'Araujo', 'Koundé', 'Iñigo', 'Balde', 'Pedri', 'Gavi', 'de_Jong', 'Raphinha', 'Lewandowski', 'Lamine'], ... } >>> Dresults = { ... ('Girona', 'Almeria'): [(2, 'Baptistao'), (24, 'Baptistao'), (37, 'Ivan_Martin'), (39, 'Dovbyk'), (43, 'Dovbyk'), (71, 'Savio'), (85, 'Stuani')], ... ('Girona', 'Celta'): [(91, 'Herrera')], ... ('Osasuna', 'Girona'): [(16, 'Ivan_Martin'), (25, 'Budimir'), (55, 'Budimir'), (71, 'Dovbyk'), (80, 'Tsygankov'), (90, 'Aleix_Garcia')], ... ('Rayo', 'Girona'): [(5, 'Alvaro'), (42, 'Dovbyk'), (65, 'Savio')], ... ('Barça', 'Rayo'): [(10, 'Lewandowski'), (65, 'Lamine'), (79, 'Lewandowski')], ... }
With this aim, it is requested that in the module goals (file goals.py) you do the two following functions. First the function
gen_goal_stats(Dplayers, Dresults, team)
such that given
Dplayers, adictlike the first one described above,
Dresults, adictlike the second one described above,
team, astr,returns a dictionary where the key is the player name (
str) and the associated value is a list of pairs (tuple) with the name of the team he scored against and the minute fo the goal.
For example, given the dictionaries above, the call gen_goal_stats(Dresults, Dplayers, 'Girona') should return the following dict:
>>> Dgoals = gen_goal_stats(Dplayers, Dresults, 'Girona') >>> DgoalsE = {'Ivan_Martin': [('Almeria', 37), ('Osasuna', 16)], ... 'Dovbyk': [('Almeria', 39), ('Almeria', 43), ('Osasuna', 71), ('Rayo', 42)], ... 'Stuani': [('Almeria', 85)], ... 'Herrera': [('Celta', 91)], ... 'Tsygankov': [('Osasuna', 80)], ... 'Aleix_Garcia': [('Osasuna', 90)]}
Test sets are available in the file gen_goal_stats-test.txt.
Second, the function
sort_by_minute(Dgoals)
such that given Dgoals a dict like the one generated by the previous funtion modifies it leaving the all the goals lists ordered decreasingly by the minute of scoring.
For example:
>>> Dgoals = gen_goal_stats(Dplayers, Dresults, 'Girona') >>> sort_by_minute(Dgoals) >>> sortedDgoals = { ... 'Ivan_Martin': [('Almeria', 37), ('Osasuna', 16)], ... 'Dovbyk': [('Osasuna', 71), ('Almeria', 43), ('Rayo', 42), ('Almeria', 39)], ... 'Stuani': [('Almeria', 85)], ... 'Herrera': [('Celta', 91)], ... 'Tsygankov': [('Osasuna', 80)], ... 'Aleix_Garcia': [('Osasuna', 90)]} >>> if Dgoals == sortedDgoals: ... True ... else: ... (Dgoals, sortedDgoals) True
Test sets are available in the file sort_by_minute-test.txt.