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 (2016, retired 2019) Dictionaries Teacher Stats

Richard A
PLUS
Richard A
Courses Plus Student 10,121 Points

Slight Roadblock :(

Please excuse me for not following the Python rule of 'explicit is better than implicit'. I just want to get through this challenge and for some reason, it is not accepting my answer. Logically, it makes sense to me how I constructed the method: create an empty list, loop the through the values (the courses) and append those values onto the empty list. I'm not sure what I'm doing wrong. Can anyone help?

The directions say to...

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

teachers.py
# 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 num_teachers(d):
    return len(d.keys())

def num_courses(d):
    return sum(len(x) for x in d.values())

def courses(d):
    result = [] #create empty list
    for x in d.values(): # loop through the values of given dict: the courses
        result.extend(x) # extend the values onto the empty list: result        
    return result

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have mixed using tabs and spaces. Replaces the tabs with spaces in the lines:

        result.extend(x) # extend the values onto the empty list: result        
    return result
Richard A
Richard A
Courses Plus Student 10,121 Points

My gosh! I pressed Enter on the penultimate line, deleted the white space and submitted the answer and then it accepted it. That was utterly frustrating for such a small detail :( I don't know if it's possible but I wish there was a more detailed error message than "Bummer! Please try again."