Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

Something wrong with courses code?

my function courses isn't returning what I want. Or, should I say, I think it should return the correct answer.

From my view - I have the correct function, I created an empty list and created a for loop which found the values and appended the list. Finally I returned the total number correctly(I think!)

Guidance would be appreciated

def num_teachers(teachers):
    total_teachers = list(teachers.keys())

def num_courses(teachers):
    total_courses = (sum(map(len, teachers.values())))

def courses(teachers):
    total_courses = []
    for number in teachers.values():
    return total_courses

3 Answers

Did you by any chance mix spaces and tabs? Or copy and paste? I think that can cause a problem sometimes.

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

I didn’t paste it from anywhere, though was trying it in workspaces while trying it, but a re-write will be a good shout when I get home!

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

I re-wrote everything and it sailed through. Frustrating mistake - thanks for your help!

At the moment, the function returns a list of all the values of whatever dictionary is passed in, so assuming assuming you feed it with the challenge dictionary:

['jQuery Basics', 'Node.js Basics', 'Python Basics', 'Python Collections']

You say that it's not returning what you want, what were you expecting the output to be?

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

The challenge reads as follows: "Great work! OK, you're doing great so I'll keep increasing the difficulty. For this step, make another new function named courses that will, again, take the dictionary of teachers and courses. courses, though, should return a single list of all of the available courses in the dictionary. No teachers, just course names!"

The code I've got doesn't work to pass although I get no guidance just a Try Again error

Is that task 3? Your code passes with me.

Sean Clayton
Sean Clayton
Courses Plus Student 1,029 Points

I get this when I try and check! Something broken in the system maybe?


Strange, I can't help you any further. Maybe some one from staff will be able to help.

Awesome! Glad that worked :)