From f6279ba4eb88a6017c521409bcb11b529a700310 Mon Sep 17 00:00:00 2001 From: Lauren Dawnkaski Date: Thu, 17 Oct 2024 09:52:29 -0400 Subject: [PATCH] Checkpoint 1 I was stuck on the very first one because I was trying to use the count command that we used in the pipes lab. For some reason it wasn't working so I had to do some research and discovered the len() command that works in scenarios like this. I was then able to use this command on some of the other problems. --- friend_functions.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/friend_functions.py b/friend_functions.py index 6f5ecf7..fc96b76 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -17,7 +17,7 @@ def count_people(people): >>> count_people(friends) 10 """ - raise NotImplementedError() + return len(people) def get_email(people, name): """Returns the named person's email address. If there is no such person, returns None. @@ -27,7 +27,11 @@ def get_email(people, name): >>> get_email(friends, "Tad Winters") None """ - raise NotImplementedError() + for person in people: + if person["name"]==name: + return person["email"] + else: + 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. @@ -37,7 +41,12 @@ def count_favorite_colors(people, name): >>> count_favorite_colors(family, "Raphael Chambers") 1 """ - raise NotImplementedError() + for person in people: + if person["name"]==name: + return len(person["favorite_colors"]) + else: + return None + def people_who_like_color(people, color): """Returns a list containing only those people who like the given color. @@ -57,7 +66,11 @@ def people_who_like_color(people, color): >>> people_who_like_color(family, "indigo") [] """ - raise NotImplementedError() + people_who_like_color=[] + for person in people: + if color in person["favorite_colors"]: + people_who_like_color.append(person) + return people_who_like_color def count_people_who_like_color(people, color): """Returns the number of people who like a given color. @@ -67,7 +80,11 @@ def count_people_who_like_color(people, color): >>> count_people_who_like_color(family, "orange") 1 """ - raise NotImplementedError() + people_who_like_color=[] + for person in people: + if color in person["favorite_colors"]: + people_who_like_color.append("person") + return len(people_who_like_color) def get_color_dict(people): """Returns a dict showing how many people like each color. @@ -86,8 +103,14 @@ def get_color_dict(people): "orange": 1, } """ - raise NotImplementedError() - + color_dict={} + for person in people: + for color in person["favorite_colors"]: + if color in color_dict: + color_dict[color]=color_dict[color]+1 + else: + color_dict[color]=1 + return color_dict