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.
This commit is contained in:
Cory Dean Chung 2023-08-14 15:20:12 -04:00
parent ed792e58ee
commit bb558ccbd7
1 changed files with 9 additions and 9 deletions

View File

@ -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