Fixed some more things with the other functions, still have to do the

get_color_dict.

I'm not sure why get_color_dict is not working, but I think that it is
not adding to the frequency when it encounters a second person with
the color in their favorites, because it is showing 1 instead of 2 for
some.
This commit is contained in:
root 2024-10-14 11:58:42 -04:00
parent 0119963833
commit 010dd82161
1 changed files with 11 additions and 7 deletions

View File

@ -33,8 +33,8 @@ def get_email(people, name):
for person in people: for person in people:
if person["name"] == name: if person["name"] == name:
return person["email"] return person["email"]
else: else:
return None return None
def count_favorite_colors(people, name): def count_favorite_colors(people, name):
"""Returns the number of colors liked by the named person. If there is no such person, returns None. """Returns the number of colors liked by the named person. If there is no such person, returns None.
@ -50,8 +50,8 @@ def count_favorite_colors(people, name):
for color in person["favorite_colors"]: for color in person["favorite_colors"]:
num_fav_colors = num_fav_colors + 1 num_fav_colors = num_fav_colors + 1
return num_fav_colors return num_fav_colors
else: else:
return None return None
def people_who_like_color(people, color): def people_who_like_color(people, color):
"""Returns a list containing only those people who like the given color. """Returns a list containing only those people who like the given color.
@ -75,7 +75,7 @@ def people_who_like_color(people, color):
for person in people: for person in people:
if color in person["favorite_colors"]: if color in person["favorite_colors"]:
who_likes_this_color.append(person) who_likes_this_color.append(person)
return who_likes_this_color return who_likes_this_color
def count_people_who_like_color(people, color): def count_people_who_like_color(people, color):
"""Returns the number of people who like a given color. """Returns the number of people who like a given color.
@ -108,8 +108,12 @@ def get_color_dict(people):
"orange": 1, "orange": 1,
} }
""" """
raise NotImplementedError() color_dict = {}
freq = 0
for person in people:
for fav_color in person["favorite_colors"]:
color_dict[fav_color] = freq + 1
return color_dict