I got the count_favorite_colors function to work.

Still using list iteration, not sure if I should be...
This commit is contained in:
root 2024-10-13 21:21:21 -04:00
parent 9bc09ed4db
commit a82e20884f
1 changed files with 8 additions and 1 deletions

View File

@ -44,7 +44,14 @@ def count_favorite_colors(people, name):
>>> count_favorite_colors(family, "Raphael Chambers")
1
"""
raise NotImplementedError()
num_fave_colors = 0
for person in people:
if person["name"] == name:
for color in person["favorite_colors"]:
num_fav_colors = num_fav_colors + 1
return num_fav_colors
else:
return None
def people_who_like_color(people, color):
"""Returns a list containing only those people who like the given color.