擅长:python、mysql、java
<p>硬编码所需的索引不是一个好主意;我建议您将其移到参数中。其他更改如下:</p>
<pre><code>def extra_points(dict_, index):
return max( # Return maximum
( # From iterator
(name, score_list[index]) # For name-score[index] tuples
for name, score_list in dict_.items() # In dict_
),
key=lambda x: x[1] # Check the max by score[index]
)[0] # Get the name (zero element)
raw_player_score = {
'Matt': [3, 5, 5, 4, 6, 9],
'Kyle': [6, 9, 11, 5, 4, 3,],
'Emily': [4, 4, 5, 2, 1, 5]
}
print(extra_points(raw_player_score, 1))
</code></pre>
<blockquote>
<p><code>Kyle</code></p>
</blockquote>