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 trial

Python Python Collections (Retired) Dictionaries Dictionary Iteration

Andrea Bianchi
Andrea Bianchi
9,127 Points

Problem with the last challenge.

At the end of the 3rd I get an error "the first no longer pass" I go back to challenge 1 and rewrite the same code that passed before. I get this strange error message: "most_classes() returned Dave McFarland expected Jason Seifer"

Where is Dave McFarland hidden in my code ??

teachers= {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'], 'Kenneth Love': ['Python Basics', 'Python Collections']}

def most_classes(teachers): maxNum = 0 name = '' for k,v in teachers.items(): if len(v) > maxNum: name = k return name

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Your code didn't properly formatted with Markdown codeblock, it's quite hard to read, but I think that the problem is that inside the for loop, after if len(v) > maxNum:, you should assign a new value to maxNum. maxNum = len(v), otherwise, maxNum will always stay 0, the code won't return the correct value.

Andrea Bianchi
Andrea Bianchi
9,127 Points

Now everything is fine. Thanks. I still wonder why the error was found during the 3rd challenge and not immediately at the end of the 1st. Maybe in the 1st challenge the check is on the syntax only.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Every time you submit code to be validated, that code is run through all of the previous steps of the code challenge before it runs through the current step. So if step 3 introduces a breaking bug, step 1 will say it's broken because step 1 couldn't run.