generated from mwc/lab_weather
people_who_like_color is working
I found this function a bit easier to work with after I had some trouble with the previous ones. The lines I added at the end are proving very useful to testing the functions and understanding how they work.
This commit is contained in:
parent
e45fa894a1
commit
36bee1bf5f
|
@ -41,12 +41,6 @@ def count_favorite_colors(people, name):
|
|||
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||
1
|
||||
"""
|
||||
'''for person in people:
|
||||
if person["name"]== name:
|
||||
colors = person["favorite_colors"]
|
||||
return len(colors)
|
||||
elif person'''
|
||||
|
||||
for person in people:
|
||||
if person["name"]== name:
|
||||
colors = person["favorite_colors"]
|
||||
|
@ -54,11 +48,7 @@ def count_favorite_colors(people, name):
|
|||
else:
|
||||
return "None"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def people_who_like_color(people, color):
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
|
@ -78,12 +68,12 @@ def people_who_like_color(people, color):
|
|||
>>> people_who_like_color(family, "indigo")
|
||||
[]
|
||||
"""
|
||||
'''for person in people:
|
||||
for favorite_colors, color in people.favorite_colors():
|
||||
like_color = []
|
||||
like_color.append(["name"])
|
||||
return like_color'''
|
||||
|
||||
like_color = []
|
||||
for person in people:
|
||||
if color in person["favorite_colors"]:
|
||||
like_color.append(person["name"])
|
||||
return like_color
|
||||
|
||||
|
||||
def count_people_who_like_color(people, color):
|
||||
"""Returns the number of people who like a given color.
|
||||
|
@ -127,5 +117,5 @@ print("email is", email)
|
|||
favcolor = count_favorite_colors(friends, "Yulix Reynolds")
|
||||
print ("# of fav colors is", favcolor)
|
||||
|
||||
#like_color = people_who_like_color(family, "red")
|
||||
#print("People who like red:", like_color)
|
||||
like_color = people_who_like_color(family, "aqua")
|
||||
print("People who like red:", like_color)
|
Loading…
Reference in New Issue