Checkpoint 1 commit 4: Wrote people_who_like_color

I again compared the output to the sample output. I originally only
returned the names of the people based on how I understood the
docstring as opposed to returning all the information of the people.
This commit is contained in:
Cory Dean Chung 2023-08-14 14:39:31 -04:00
parent 87f87eab0b
commit ffb18b847b
1 changed files with 6 additions and 11 deletions

View File

@ -31,13 +31,6 @@ def get_email(people, name):
return None
def count_favorite_colors(people, name):
"""Returns the number of colors liked by the named person. If there is no such person, returns None.
>>> count_favorite_colors(family, "Tad Winters")
2
>>> count_favorite_colors(family, "Raphael Chambers")
1
"""
color_count = 0
for person in people:
if person["name"] == name:
@ -46,9 +39,6 @@ def count_favorite_colors(people, name):
return color_count
return None
print count_favorite_colors(family, "Tad Winters")
print count_favorite_colors(family, "Raphael Chambers")
def people_who_like_color(people, color):
"""Returns a list containing only those people who like the given color.
>>> people_who_like_color(family, "yellow")
@ -67,7 +57,12 @@ def people_who_like_color(people, color):
>>> people_who_like_color(family, "indigo")
[]
"""
raise NotImplementedError()
people_list = []
for person in people:
for colors in person["favorite_colors"]:
if colors == color:
people_list.append(person)
return people_list
def count_people_who_like_color(people, color):
"""Returns the number of people who like a given color.