Belgium has participated eleven times in the finals of the World Cup soccer, and will return on the WC2014 for the first time since its last qualification for the finals of the WC2002 in Japan and South Korea. The finals of a World Cup always begins with a group stage, where the participating countries are distributed over a number of groups. The number of groups and the number of countries per group differs between championships, but each group is always assigned a unique label in the form of an uppercase letter. Within each group, each country plays once against each of the other countries.

Your task is to generate an overview of the standings in a given group based on the results of a number of games played in the group stage of a World Cup. The list of matches played is stored in a text file containing the following information for each match on a separate line: i) name of the home team, ii) name of the visiting team, iii) final score of the match, and iv) the uppercase letter assigned to the group of both teams (countries). The individual information fields about a match are separated by commas and the final score is given as the number of goals scored by each team, separated by a hyphen (-). In addition, the file with the matches played may also contain empty lines and comment lines starting with a pound sign (#). Such lines must be ignored.

See the examples below to get an idea of the format that needs to be used to generate an overview of the standings for a particular group. The overview should display the following statistics for each country in the group: i) number of matches played (P), ii) number of matches won (W), iii) number of matches lost (L), iv) number of matches that ended in a draw (D), v) number of goals scored (F), vi) number of goals conceded (A), vii) goal difference (S) and viii) number of points (Pts). The goal difference is the number of goals scored minus the number of goals conceded. A team gets three points for each match won and a single point for each match that ended in a draw. The overview must list the countries in the group in sorted order, first according to decreasing number of points, then according to decreasing goal difference, and finally in increasing alphabetic order according to the name of the country. In addition, the format should look like in the examples shown below, where a table is drawn and the label of the group is centred on top of the table.

Assignment

Example

In the following interactive session we assume that the text file worldcup2010.txt1 is located in the current directory.

>>> stats = processMatches('worldcup2010.txt')
>>> stats['A']
{'Uruguay': [1, 1, 1, 3, 2], 'Mexico': [0, 2, 1, 1, 5], 'France': [2, 0, 1, 6, 2], 'South Africa': [1, 1, 1, 3, 4]}
>>> stats['B']
{'Argentina': [2, 1, 0, 3, 2], 'Greece': [3, 0, 0, 3, 0], 'Nigeria': [1, 2, 0, 2, 3], 'South Korea': [0, 3, 0, 0, 3]}
>>> stats['F']
{'Paraguay': [2, 0, 1, 5, 2], 'Slovakia': [0, 0, 3, 3, 3], 'New Zealand': [0, 2, 1, 2, 6], 'Italy': [1, 1, 1, 4, 3]}
>>> showGroup(stats, 'A')
                            GROUP A                            
+-----------------------+-----+-------------------------+-----+
|                       |   P |   W   L   D   F   A   S | Pts |
+-----------------------+-----+-------------------------+-----+
|                France |   3 |   2   0   1   6   2   4 |   7 |
|               Uruguay |   3 |   1   1   1   3   2   1 |   4 |
|          South Africa |   3 |   1   1   1   3   4  -1 |   4 |
|                Mexico |   3 |   0   2   1   1   5  -4 |   1 |
+-----------------------+-----+-------------------------+-----+
>>> showGroup(stats, 'D')
                            GROUP D                            
+-----------------------+-----+-------------------------+-----+
|                       |   P |   W   L   D   F   A   S | Pts |
+-----------------------+-----+-------------------------+-----+
|               Germany |   3 |   2   1   0   5   1   4 |   6 |
|                 Ghana |   3 |   1   1   1   3   3   0 |   4 |
|                Serbia |   3 |   1   1   1   3   4  -1 |   4 |
|             Australia |   3 |   1   2   0   3   6  -3 |   3 |
+-----------------------+-----+-------------------------+-----+
>>> showGroup(stats, 'F', 'groupF.txt')