Code: Alles auswählen
#!/usr/bin/env python3
import sys
if len(sys.argv) != 2:
sys.exit()
FN=sys.argv[1]
d={} #values={N:[w,d,l,gp,gm,ge,p]}
with open(FN) as f:
for game in f:
team1,goals1,goals2,team2=game.rstrip().split(',')
for team in team1,team2:
if team not in d:
d[team]=[0,0,0,0,0,0,0]
d[team1][3]+=int(goals1); d[team2][4]+=int(goals1)
d[team1][4]+=int(goals2); d[team2][3]+=int(goals2)
d[team1][5]=d[team1][3]-d[team1][4]; d[team2][5]=d[team2][3]-d[team2][4]
if goals1==goals2:
d[team1][1]+=1; d[team2][1]+=1
d[team1][6]+=1; d[team2][6]+=1
elif goals1>goals2:
d[team1][0]+=1; d[team2][2]+=1
d[team1][6]+=3
else:
d[team1][2]+=1; d[team2][0]+=1
d[team2][6]+=3
out=sorted(d.items(), key=lambda t:(-t[1][6],-t[1][5],-t[1][0],t[0]))
print(" Name # w d l + - = P")
print("--------------------------------------------------")
for n,i in enumerate(out,1):
print("{:>25s} {:2d} {:2d} {:2d} {:2d} {:2d} {:2d} {:3d} {:2d}".format(i[0],n,*i[1]))
Code: Alles auswählen
$ ./t.py scripting_contest-game_results_utf8.csv
Name # w d l + - = P
--------------------------------------------------
FC Zürich 1 16 10 10 70 59 11 58
Grasshopper Club Zürich 2 17 7 12 79 70 9 58
BSC Young Boys 3 16 10 10 66 58 8 58
FC Lausanne-Sport 4 16 6 14 58 63 -5 54
FC St. Gallen 1879 5 14 9 13 59 58 1 51
FC Sion 6 14 8 14 55 62 -7 50
Servette FC 7 13 9 14 76 73 3 48
FC Luzern 8 14 6 16 75 79 -4 48
FC Basel 1893 9 11 8 17 66 77 -11 41
FC Lugano 10 10 5 21 58 63 -5 35