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 trialErik Burmeister
Python Web Development Techdegree Graduate 17,108 PointsTeacher Stats step 4 explanation
I've been using Jupyter Notebook to help me write notes and test out the challenge questions. The code below served as my solution to step 4. In the code, I commented out a line and it worked as a solution here, however, in Jupyter I need the line of code for the function to work properly.
I'd really appreciate if anyone could explain to me why that is.
If anyone has a better solution to this problem, I'd love to see it. I'm trying to get into the headspace that there's more than one way to tackle a problem. It would be great to learn a new way of thinking when it comes to programming with Python.
def most_courses(dict):
teacher = ''
max_count = 0
for t,c in dict.items():
if len(c) > max_count:
teacher = t
#max_count += len(c)
return teacher
2 Answers
KRIS NIKOLAISEN
54,972 PointsWouldn't it be just:
max_count = len(c)
since you are updating the value if it is largest instead of adding to the previous value.
Erik Burmeister
Python Web Development Techdegree Graduate 17,108 PointsYou're right, it worked. I see what you mean.
The whole concept of dictionaries is still sinking in, so something like this is still kind of going over my head.