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 trialDaniel Adari
3,577 PointsCreate a function named most_courses: Can't figure out how to continue.
Hi, I need to set best_techer to the key of the best value. I know that I have a messy code, I would love to get some help with that too. Thanks!
# 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.
def num_teachers(some_dict):
count = 0
for keys in some_dict:
count += 1
return count
def num_courses(some_dict):
courses = 0
for values in some_dict.values():
for inner_values in values:
courses += 1
return courses
def courses(some_dict):
courses_list = []
for values in some_dict.values():
for inner_values in values:
courses_list.append(inner_values)
return courses_list
def most_courses(some_dict):
current_max = 0
new_max = 0
best_teacher = ""
for values in some_dict.values():
for inner_values in values:
new_max += 1
if new_max > current_max:
current_max = new_max
best_teacher = ????
return best_teacher
1 Answer
Steven Parker
231,269 PointsIt looks like you're really close!
Here's a hint: You might want to use "items" instead of "values" for iterating, as it will give you the current teacher name along with the list of courses at the same time.
I'll bet you can get it from here.
Bonus hint: Instead of using an inner loop to count the courses one at a time, you could use the length of the list.