From bb558ccbd7617da0485e2a2b6c3f9d010419751c Mon Sep 17 00:00:00 2001 From: Cory Dean Chung Date: Mon, 14 Aug 2023 15:20:12 -0400 Subject: [PATCH] Checkpoint 1 final commit: Finished all functions. I didn't really get stuck on this one. I did take some time to think about how I could break the problem into two parts. Because I already had a function that could count the number of people who like a color, I just had to determine how to know all the colors that are liked. --- friend_functions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/friend_functions.py b/friend_functions.py index 1efb2e6..e9ff8c7 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -48,13 +48,6 @@ def people_who_like_color(people, color): return people_list def count_people_who_like_color(people, color): - """Returns the number of people who like a given color. - - >>> count_people_who_like_color(family, "red") - 2 - >>> count_people_who_like_color(family, "orange") - 1 - """ people_liking_color = people_who_like_color(people,color) people_count = 0 for person in people_liking_color: @@ -78,8 +71,15 @@ def get_color_dict(people): "orange": 1, } """ - raise NotImplementedError() - + # First, get a dictionary of all the colors that are liked. + color_dict = {} + for person in people: + for colors in person["favorite_colors"]: + color_dict[colors] = "0" + # Then, assign the correct numbers to each color. + for key in color_dict: + color_dict[key] = count_people_who_like_color(people,key) + return color_dict