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

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

it does return courses, why it's not ok?

please somebody

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(value):
    teachers = []
    for x in value:
        teachers.append(x)
    return len(teachers)

def num_courses(value):
    cours = []
    for a in value.values():
        for b in a:
            cours.append(b)
    return len(cours)

def courses(value):
    lesson = []
    for a in value.values():
        for b in a:
            lesson.append(b)
        return lesson

1 Answer

Hey Oszkar,

Your code works if you unindent your return statement. Right now it returns lesson with only one item in it since it is inside of your for loop.

def courses(value):
    lesson = []
    for a in value.values():
        for b in a:
            lesson.append(b)
    return lesson # Bring it outside of the for loop

Cheers!

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

umbelivable, i did this mistake to many times, i just wrote to my teacher and now i feel shy because i realized how blind i am. thank you very much. the funny thing is that i made it pycharm correctly and here i am blind....