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

Steven Hender
Steven Hender
5,830 Points

Python Collections: Challenge Task 4 of 5 - Bummer: Couldn't find `most_courses`

Here is the challenge question:

"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.

def most_courses(courses): max_count =0 max_teachername ="" for item in courses: teacher_name=(item) i = coureses[item] if isinstance(i,str): a=1 if a>max_count: max_count = a max_teachername = teacher_name else: a = len(i) if a>max_count: max_count = a max_teachername = teacher_name return(max_teachername)

The error I receive seems quite basic that I have not correctly defined the function "most_courses" - obviously I am missing something basic. Anyone have any ideas?

2 Answers

Steven Parker
Steven Parker
229,771 Points

Python is really hard to debug when not formatted! Use Markdown for code formatting (here's a video about it). And be sure to include your complete challenge code so we can get to the task that has the issue.

Steven Hender
Steven Hender
5,830 Points

Thanks, I will use this next time! for some reason my code now works - thankyou :)

Steven Parker
Steven Parker
229,771 Points

You could still add the formatting here for the benefit of future readers. :wink: