diff --git a/friend_functions.py b/friend_functions.py index c4741f0..6e50d24 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -31,7 +31,7 @@ def get_email(people, name): if person["name"] == name: return person["email"] else: - return "None" + 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. @@ -46,7 +46,7 @@ def count_favorite_colors(people, name): colors = person["favorite_colors"] return len(colors) else: - return "None" + return None @@ -69,9 +69,11 @@ def people_who_like_color(people, color): [] """ like_color = [] + d={} for person in people: if color in person["favorite_colors"]: - like_color.append(person["name"]) + d = {"name": person["name"], "email": person["email"], "favorite_colors":person["favorite_colors"]} + like_color.append(d) return like_color @@ -88,7 +90,9 @@ def count_people_who_like_color(people, color): if color in person["favorite_colors"]: like_color2.append(person["name"]) return len(like_color2) + +from collections import Counter def get_color_dict(people): """Returns a dict showing how many people like each color. Any color liked by any of the people will be included, and only colors @@ -106,7 +110,17 @@ def get_color_dict(people): "orange": 1, } """ - raise NotImplementedError() + + + all_colors= [] + for person in people: + for color in person["favorite_colors"]: + all_colors.append(color) #gives a list of all colors liked including duplicates + + d = Counter(all_colors) + return d + + @@ -121,8 +135,11 @@ print("email is", email) favcolor = count_favorite_colors(friends, "Yulix Reynolds") print ("# of fav colors is", favcolor) -like_color = people_who_like_color(family, "aqua") -print("People who like red:", like_color) +like_color = people_who_like_color(family, "blue") +print("People who like blue:", like_color) -count_color = count_people_who_like_color(friends, "red") -print("# who like red:", count_color) \ No newline at end of file +count_color = count_people_who_like_color(family, "blue") +print("# who like blue:", count_color) + +d=get_color_dict(friends) +print(d) \ No newline at end of file