擅长:python、mysql、java
<p>你很接近!您只需更新正在函数中构建的词典,即可将学生姓名映射到其属性并返回:</p>
<pre><code>preschool_kids = {
"Suzie": ("purple", 4, "brown"),
"Michael": ("blue", 3, "blond"), "Jane":("purple",5, "black")
}
def search(values, color):
students_with_favorite_color = {}
for name,attrs in preschool_kids.items():
students_favorite_color = attrs[0]
if students_favorite_color == color:
students_with_favorite_color[name] = attrs
return students_with_favorite_color
print(search(preschool_kids, 'purple'))
</code></pre>