Python中国好声音音评分

https://img-mid.csdnimg.cn/release/static/image/mid/ask/100379523866135.jpg
https://img-mid.csdnimg.cn/release/static/image/mid/ask/952089523866120.jpg

ls = []
try:
    while True:
        a = input().split()
        if len(a) == 0:
            break
        ls.append(a)
except:
    pass
temp = {}
for i in ls:
    temp[i[1]] = temp[i[1]] if i[1] in temp else []
    temp[i[1]].append((i[0], int(i[2])))

result = []
for i in temp:
    total = 0
    for j in temp[i]:
        total += j[1]
    result.append((i, temp[i], total / len(temp[i])))

result.sort(key=lambda x: x[2], reverse=True)

for k, i in enumerate(result, 1):
    temp = "第" + str(k) + "名:" + i[0] + " ("
    for j in i[1]:
        temp += j[0] + ": " + str(j[1]) + ", "
    temp += "平均:" + str(round(i[2], 1)) + ")"
    print(temp)
    if k == 3:
        break