I just finished this code about frequency of each words but my challenge is to modify it to get the name of the winner in all games and the most total coins that he earned.
The file looks like that (I made the titles "Name , game, coins" just to understand):
Name: Game: coins:
Fred Braingame 80
Eddy Football 20
Lucy Puzzlgame 50
Mark Puzzlgame 70
Edy Football 100
Mark Football 60
Fred Puzzlgame 40
Here is the code of frequencies:
f = open("f.txt", "r")
d = dict()
for res in f:
res = res.strip()
res = res.lower()
lines = res.split()
for line in lines:
if line in d:
d[line] = d[line]+1
else:
d[line] = 1
f.close()
for key in list(d.keys()):
print("The count of {} is {}".format(key,d[key]))
The output should be like that:
Mark 130 # because he's who earned the most_total coins in all games.
# 130 is the total of coins : 70 coin + 60 coins