列出获得的最多硬币

我刚刚完成了有关每个单词出现频率的代码,但是我面临的挑战是对其进行修改,以获取所有游戏中获胜者的姓名以及他所获得的最多硬币数量。

该文件看起来像这样(为了理解,我将其命名为“名称,游戏,硬币”):

Name:     Game:          coins:
Fred      Braingame       80
Eddy      Football        20
Lucy      Puzzlgame       50
Mark      Puzzlgame       70
Edy       Football        100
Mark      Football        60
Fred      Puzzlgame       40

以下是频率代码:

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]))

输出应该是这样的:

Mark     130  # because he's who earned the most_total coins in all games.
评论