擅长:python、mysql、java
<p>如果您不需要存储每次尝试的分数,那么如果该值高于当前记录的尝试,为什么不直接替换该值呢?你知道吗</p>
<pre><code>students = {}
f = open("std_attempt_score.txt", "r")
line = f.readline()
for line in f:
line = line.rstrip()
ents = line.split(",")
student_id = ents[0]
attempt_score = int(ents[2])
score = students.setdefault(student_id, attempt_score)
if attempt_score > score:
students[student_id] = attempt_score
for student_id, score in students.items():
print("Highest score for Student", student_id, "=", score)
</code></pre>