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 trialOwen Wherry
1,508 PointsThe fourth question of this code challenge works in workspaces but not in the code challenge... what's wrong?
I realize that this code is a bit clunky, but I still don't understand why it won't work in the code challenge. I would highly appreciate it if someone knew what I am doing wrong.
# 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):
return len(dictionary)
def num_courses(dictionary):
num = 0
for value in dictionary.values():
num += len(value)
return num
def courses(dictionary):
courses = []
for value in dictionary.values():
courses += value
return courses
def most_courses(dictdef most_courses(dictionary):
new_courses = {n: len(dictionary[n]) for n in dictionary.keys()}
return list(new_courses.keys())[list(new_courses.values()).index(max(new_courses.values()))]
1 Answer
Steven Parker
231,269 PointsYou say this works in the workspace? Those last 3 lines don't look at all like Python syntax to me, the "def" line doesn't even have balanced parentheses. Look closely, maybe something didn't get pasted right.
Owen Wherry
1,508 PointsOwen Wherry
1,508 Pointsdef most_courses(dictionary): new_courses = {n: len(dictionary[n]) for n in dictionary.keys()} return list(new_courses.values()).index(max(new_courses.values()))]
This code worked great! You're right, the "def" line did not get printed right. Thanks!