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:
  • The key is a tuple with the pair of team names (str) that played.

  • The value is a list where each element represents a goal and has the form of a tuple with the minute the goal was scored (int) and the name of the player who scored str).

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, a dict like the first one described above,

  • Dresults, a dict like the second one described above,

  • team, a str,

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.