Skip to content

Commit 540045f

Browse files
committed
Finished working on the tournament challenge
1 parent ccae9af commit 540045f

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed
394 Bytes
Binary file not shown.
Binary file not shown.

tournament/tournament.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from collections import OrderedDict
2+
3+
tableformat = '{:<31}|{:>3} |{:>3} |{:>3} |{:>3} |{:>3}'
4+
15
def tally(rows):
2-
6+
37
scoreboard = {
48
"Allegoric Alaskans" : {
59
"MP" : 0,
@@ -28,48 +32,45 @@ def tally(rows):
2832
"D" : 0,
2933
"L" : 0,
3034
"P" : 0
31-
}
35+
},
3236
}
3337

3438
for i in rows:
3539
elements = i.split(';')
3640
home = elements[0]
3741
away = elements[1]
3842
result = elements[2]
39-
43+
4044
if result == 'win':
41-
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
45+
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
4246
scoreboard[away]['MP'] = scoreboard[away]['MP']+1
43-
scoreboard[home]['W'] = scoreboard[home]['W']+1
47+
scoreboard[home]['W'] = scoreboard[home]['W']+1
4448
scoreboard[away]['L'] = scoreboard[away]['L']+1
45-
scoreboard[home]['P'] = scoreboard[home]['P']+3
49+
scoreboard[home]['P'] = scoreboard[home]['P']+3
4650
#print('The home was '+home+' the away was '+away+' and the result was '+result)
4751
elif result == 'draw':
48-
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
52+
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
4953
scoreboard[away]['MP'] = scoreboard[away]['MP']+1
50-
scoreboard[home]['D'] = scoreboard[home]['D']+1
54+
scoreboard[home]['D'] = scoreboard[home]['D']+1
5155
scoreboard[away]['D'] = scoreboard[away]['D']+1
5256
scoreboard[home]['P'] = scoreboard[home]['P']+1
53-
scoreboard[away]['P'] = scoreboard[away]['P']+1
57+
scoreboard[away]['P'] = scoreboard[away]['P']+1
5458
elif result == 'loss':
55-
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
59+
scoreboard[home]['MP'] = scoreboard[home]['MP']+1
5660
scoreboard[away]['MP'] = scoreboard[away]['MP']+1
57-
scoreboard[home]['L'] = scoreboard[home]['L']+1
61+
scoreboard[home]['L'] = scoreboard[home]['L']+1
5862
scoreboard[away]['W'] = scoreboard[away]['W']+1
59-
scoreboard[away]['P'] = scoreboard[away]['P']+3
60-
61-
table = []
62-
63-
table.append("Team | MP | W | D | L | P")
64-
#output_line = str
65-
for field, v in scoreboard.items():
66-
table.append('{}|{}|{}|{}|{}|{}'.format(field, v['MP'], v['W'],v['D'],v['L'],v['P']))
67-
68-
69-
63+
scoreboard[away]['P'] = scoreboard[away]['P']+3
7064

65+
ordered = OrderedDict(sorted(scoreboard.items(), key=lambda i: i[1]['P'], reverse=True))
7166

72-
return table
67+
header = [tableformat.format('Team', 'MP', 'W', 'D', 'L', 'P',)]
68+
table = [tableformat.format(field,
69+
v['MP'],
70+
v['W'],
71+
v['D'],
72+
v['L'],
73+
v['P'],) for field, v in ordered.items() if v['MP'] > 0]
7374

74-
75+
return header + table
7576
pass

0 commit comments

Comments
 (0)