generated from mwc/lab_weather
Checkpoint 1
Feeling relieved to have gotten all the functions working. I had one l ast problem and after posting to Discord and was actually able to figure it out myself (somehow seeing it in the message board instead of the terminal made it more obvious, I ended up deleting the post from Discord since it was super specific). I found this part of the lab to be kind of challenging as it was not very straightforward and was somewhat frustrating at times. I feel like a bit more documentation or background on dictionaries could have helped, but I was ultimately able to solve the problem by searching online and trying to think each line through. It also took me a while to realize we were using a list of dictionaries and keeping that in the front of my mind helped me get past the final issues I was having.
This commit is contained in:
parent
f9ec3295a6
commit
0a4b79f4c2
|
@ -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)
|
||||
count_color = count_people_who_like_color(family, "blue")
|
||||
print("# who like blue:", count_color)
|
||||
|
||||
d=get_color_dict(friends)
|
||||
print(d)
|
Loading…
Reference in New Issue