generated from mwc/lab_weather
Fixed some more things with the other functions, still have to do the
get_color_dict. I'm not sure why get_color_dict is not working, but I think that it is not adding to the frequency when it encounters a second person with the color in their favorites, because it is showing 1 instead of 2 for some.
This commit is contained in:
parent
0119963833
commit
010dd82161
|
@ -33,8 +33,8 @@ def get_email(people, name):
|
|||
for person in people:
|
||||
if person["name"] == name:
|
||||
return person["email"]
|
||||
else:
|
||||
return None
|
||||
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.
|
||||
|
@ -50,8 +50,8 @@ def count_favorite_colors(people, name):
|
|||
for color in person["favorite_colors"]:
|
||||
num_fav_colors = num_fav_colors + 1
|
||||
return num_fav_colors
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
def people_who_like_color(people, color):
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
|
@ -75,7 +75,7 @@ def people_who_like_color(people, color):
|
|||
for person in people:
|
||||
if color in person["favorite_colors"]:
|
||||
who_likes_this_color.append(person)
|
||||
return who_likes_this_color
|
||||
return who_likes_this_color
|
||||
|
||||
def count_people_who_like_color(people, color):
|
||||
"""Returns the number of people who like a given color.
|
||||
|
@ -108,8 +108,12 @@ def get_color_dict(people):
|
|||
"orange": 1,
|
||||
}
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
color_dict = {}
|
||||
freq = 0
|
||||
for person in people:
|
||||
for fav_color in person["favorite_colors"]:
|
||||
color_dict[fav_color] = freq + 1
|
||||
return color_dict
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue