From ffb18b847bd7967d37f971958c470cff9dc6dba8 Mon Sep 17 00:00:00 2001 From: Cory Dean Chung Date: Mon, 14 Aug 2023 14:39:31 -0400 Subject: [PATCH] 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. --- friend_functions.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/friend_functions.py b/friend_functions.py index 4b2e665..2a3c313 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -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.