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:
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:
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 abovereturns the corresponding scorers dictionary also as described above
Test sets are available in the gen_Dscorers-test.txt file.