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

David Chacón
David Chacón
1,086 Points

Unsure of where I'm going wrong, teachers.py step 5/5

I can feel I'm close. I'm just not sure what I'm missing.

No answers please, just a hint in the right direction would be great!

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(teachers):
    count = 0
    for teacher in teachers:
        count += 1

    return count

def num_courses(courses):
    count = 0
    for i in courses:
        count += len(courses[i])
    return count

def courses(courses):
    count = []
    for i in courses:
        count += courses[i]
    return count

def most_courses(teacher):
    leader = 0
    teacherMost = ""
    for i in teacher:
        if len(teacher[i]) > leader:
            leader = len(teacher[i])
            teacherMost = i
    return teacherMost

def stats(teacher):
    stats = []
    for i in teacher:
        stats += [i, len(teacher[i])]

    return stats
Jamie Marsay
Jamie Marsay
8,320 Points

Hi there, David!

You're very close to the solution, but if you'd like a clue, it has to do with this line:

stats += [i, len(teacher[i])]

+= is used for adding integers to integers, not appending items to a list.

Hope this makes it slightly clearer for you!

Let me know if you need further help!

James.

1 Answer

David Chacón
David Chacón
1,086 Points

OMG James thank you! That hint was perfect! So close.... so close.