Mar-15-2019, 04:54 PM
Hi there,
I have a dictionary of classes. The class consists of data for soccer games with attributes like team, league, lists of results, lists of calculated values (floats). I want to get the sum (or the average) of these calculated values. I can easily get these sums per team because the dictionary is "keyed" by team, doing like this:
I can sort the dictionary like this, but i cant figure out how get the sum of match.hit_percentage for example by league?
Cheers :)
I have a dictionary of classes. The class consists of data for soccer games with attributes like team, league, lists of results, lists of calculated values (floats). I want to get the sum (or the average) of these calculated values. I can easily get these sums per team because the dictionary is "keyed" by team, doing like this:
for team in laglista: print(team(25), "\t", bibliotek_lag[team].liga, "\t", str(round(stats.gmean(bibliotek_lag[team].hit_percentage),2))However, i also want to be able to get the sum per legaue or any other attribute, not just by team.
I can sort the dictionary like this, but i cant figure out how get the sum of match.hit_percentage for example by league?
for match in (sorted(bibliotek_lag.values(), key=operator.attrgetter('liga'))): print(match.liga, match.lag, str(round(stats.gmean(match.hit_percentage),2))I might be way off here, i have a feeling there must be a much better way to do this...
Cheers :)