擅长:python、mysql、java
<p>由于多个键可以具有相同的值,所以您可能希望返回匹配键的列表,而不仅仅是一个键。在</p>
<pre><code>def min_keys(d, index):
# Initialize lists
values = []
matches = []
# Append tuple items to list based on index
for t in list(d.values()):
values.append(t[index])
# If the item matches the min, append the key to list
for key in d:
if d[key][index] == min(values):
matches.append(key)
# Return a list of all keys with min value at index
return matches
</code></pre>