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 trialChotipat Metreethummaporn
1,129 PointsWhat wrong with my code? I think it works really fine, but I still got Bummer. (Task 4) --> (most_courses)
- I am new with this language, but I never give up! -
I really appreciate if someone hints me how to do with task 4.
Thank you very much!
# 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(dictionary):
length_dict = len(dictionary)
return length_dict
def num_courses(dictionary):
number = 0
for key in dictionary:
lists = dictionary["{}".format(key)]
real = len(lists)
number += real
print(number)
return number
def courses(dictionary):
result = []
for key in dictionary:
lists = dictionary["{}".format(key)]
result.extend(lists)
print(result)
return result
def most_courses(dictionary):
teacher = ''
max_count = 0
for key in dictionary:
lists = dictionary["{}".format(key)]
for value in lists:
compare_count = len(value)
if compare_count > max_count:
max_count = compare_count
teacher = key
return teacher
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsYou are counting the length of each item in the list. This is the length of the course name.
Remove the in for
loop, and compare the length of the courses lists
. Hint: replace len(value)
with len(lists)
Post back if you need more help. Good luck!
Chotipat Metreethummaporn
1,129 PointsChotipat Metreethummaporn
1,129 PointsOh! I just a little bit of mistake, alright! I can pass the test right now! Thank you very much.