generated from mwc/lab_weather
Checkpoint 1 commit 4: Wrote people_who_like_color
I again compared the output to the sample output. I originally only returned the names of the people based on how I understood the docstring as opposed to returning all the information of the people.
This commit is contained in:
parent
87f87eab0b
commit
ffb18b847b
|
@ -31,13 +31,6 @@ def get_email(people, name):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def count_favorite_colors(people, name):
|
def count_favorite_colors(people, name):
|
||||||
"""Returns the number of colors liked by the named person. If there is no such person, returns None.
|
|
||||||
|
|
||||||
>>> count_favorite_colors(family, "Tad Winters")
|
|
||||||
2
|
|
||||||
>>> count_favorite_colors(family, "Raphael Chambers")
|
|
||||||
1
|
|
||||||
"""
|
|
||||||
color_count = 0
|
color_count = 0
|
||||||
for person in people:
|
for person in people:
|
||||||
if person["name"] == name:
|
if person["name"] == name:
|
||||||
|
@ -46,9 +39,6 @@ def count_favorite_colors(people, name):
|
||||||
return color_count
|
return color_count
|
||||||
return None
|
return None
|
||||||
|
|
||||||
print count_favorite_colors(family, "Tad Winters")
|
|
||||||
print count_favorite_colors(family, "Raphael Chambers")
|
|
||||||
|
|
||||||
def people_who_like_color(people, color):
|
def people_who_like_color(people, color):
|
||||||
"""Returns a list containing only those people who like the given color.
|
"""Returns a list containing only those people who like the given color.
|
||||||
>>> people_who_like_color(family, "yellow")
|
>>> people_who_like_color(family, "yellow")
|
||||||
|
@ -67,7 +57,12 @@ def people_who_like_color(people, color):
|
||||||
>>> people_who_like_color(family, "indigo")
|
>>> people_who_like_color(family, "indigo")
|
||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
people_list = []
|
||||||
|
for person in people:
|
||||||
|
for colors in person["favorite_colors"]:
|
||||||
|
if colors == color:
|
||||||
|
people_list.append(person)
|
||||||
|
return people_list
|
||||||
|
|
||||||
def count_people_who_like_color(people, color):
|
def count_people_who_like_color(people, color):
|
||||||
"""Returns the number of people who like a given color.
|
"""Returns the number of people who like a given color.
|
||||||
|
|
Loading…
Reference in New Issue