Scorers

We want to know the scorers of a series of World Cup matches. Specifically, we have a dictionary of matches where the key is a match represented by a tuple with the two team names (str) and the associated value is the list of goals of the match where each goal is represented by the following 3-component tuple:

  • the name of the player who scored the goal (str)

  • the minute (int)

  • whether it has been a penalty or not (bool)

For example:


>>> Dmatches = {('FRA', 'MAR'): [('Hernández', 4, False), ('Kolo', 78, False)],
... ('ARG', 'CRO'): [('Messi', 34, False), ('Alvarez', 39, False), ('Alvarez', 69, False)],
... ('ARG', ' FRA'): [('Messi', 22, True), ('DiMaría', 35, False), ('Mbappé', 80, True), ('Mbappé', 81, False), ('Messi', 108, False), ('Mbappé', 117, False)]}

The goal is to build a dictionary of scorers where the key is the player name (str) and its associated value is a (list) with three components:

  • an int with the total number of goals this player has scored

  • an int with the number of those goals that have been penalty goals

  • a list of the matches where the player scored

For example:


>>> Dscorers = {'Hernández': [1, 0, [('FRA', 'MAR')]],
... 'Kolo': [1, 0, [('FRA', 'MAR')]], 
... 'Messi': [3, 1, [('ARG', 'CRO'), ('ARG', ' FRA'), ('ARG', ' FRA')]], 
... 'Alvarez': [2, 0, [('ARG', 'CRO'), ('ARG', 'CRO')]],
... 'DiMaría': [1, 0, [('ARG', ' FRA')]],
... 'Mbappé': [3, 1, [('ARG', ' FRA'), ('ARG', ' FRA'), ('ARG', ' FRA')]]}

Write the following Python function in the football module (file football.py):

gen_Dscorers(Dmatches)

given Dmatches, a dictionary of matches as described above

returns the corresponding scorers dictionary also as described above

Test sets are available in the gen_Dscorers-test.txt file.