Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEmil Hejlesen
3,014 Pointsi don't understand
please help i dont understand this one
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.
dict = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
'Kenneth Love': ['Python Basics', 'Python Collections']}
def num_teachers(dict):
teachers = 0
for x in dict.keys():
teachers += 1
return teachers
def num_courses(dict):
courses = 0
for x in dict.values():
for y in x:
courses += 1
return courses
def courses(dict):
list = []
for x in dict.values():
for y in x:
list.append(y)
return list
def most_courses(teacher ):
1 Answer
Grigorij Schleifer
10,365 PointsHi Emil, check this one out:
def most_courses(dict):
high = 0 # needed to store the number of courses and use it for comparison
for teacher in dict:
if len(dict[teacher]) > high: # if the number of courses exseed the previous number
boss = [] # always start with a fresh list, previous teachers names are removed
boss.append(teacher) # append the name
return "".join(boss) # join the list containing the name of the boss teacher to a string
Makes sense?
Emil Hejlesen
3,014 PointsEmil Hejlesen
3,014 Pointsyes it does thank you so much :)
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey Emil, you are very welcome!