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 trialnorman cole
2,756 Pointswhats wrong with my code it works in pycharm 3.6
Wow, I just can't stump you! OK, two more to go. I think this one's my favorite, though. Create a function named most_courses that takes our good ol' teacher dictionary. most_courses should return the name of the teacher with the most courses. You might need to hold onto some sort of max count variable.
# 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.
dictionary = {"Andrew Chalkley": ['jQuery Basics', 'Node.js Basics'],
"Kenneth Love": ["Python Basics", "Python Collections",]
"Jay": ["bbbb", "aaaa", "cccc"]}
def num_teachers(dictionary):
box1 = 0
for key in dictionary.keys():
box1 += 1
return box1
def num_courses(dictionary):
box2 = 0
for dict in dictionary:
box2 += len(dictionary[dict])
return box2
def courses(dictionary):
single_list = []
for value in dictionary.values():
single_list.extend(value)
return single_list
def most_courses(dictionary):
for key, value in dictionary.items():
max_count = 3
if len(value) == max_count:
return key
1 Answer
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsThey've given you an example of what the teacher/course data will look like. But this isn't necessarily the real test data. You've hard coded 3 as the max count. You need to compute it from the data. Also I think you missed a comma in the sample dictionary data before where you added an item.