created the first two functions of friend_functions

I didn't properly read the instructions and I kept getting confused by what the data looked like so I created a trials
folder and I used it to dissect the data. Once it was clear that I was looking at a list of dictionaries, it became
very easy to create my first two functions. It's necessary to know what the dataset looks like structurally.
This commit is contained in:
ilmabura
2025-10-20 16:01:43 -04:00
parent b8fc500299
commit 2899a3250a
2 changed files with 105 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
# Your job is to complete these functions. Remove the NotImplementedError from
# each and instead write code which returns the expected values.
from people import *
def count_people(people):
"""Counts the number of people.
@@ -17,7 +17,9 @@ def count_people(people):
>>> count_people(friends)
10
"""
raise NotImplementedError()
count=len(people)
return count
def get_email(people, name):
"""Returns the named person's email address. If there is no such person, returns None.
@@ -27,7 +29,11 @@ def get_email(people, name):
>>> get_email(friends, "Tad Winters")
None
"""
raise NotImplementedError()
for n in people:
if n['name']== name:
return n['email']
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.
@@ -90,5 +96,4 @@ def get_color_dict(people):
print(get_email(friends, "Tad Winters"))