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

Great work! OK, you're doing great so I'll keep increasing the difficulty. For this step, make an

can some one help challenge 3

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

def num_courses(a_dict):
    total = 0
    for key, value in a_dict.items():
        total += len(value)
    return total

3 Answers

Alexandra Barnett
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,473 Points

Hi Jalil! Great work so far!

You need to make a function and create an empty list (master list) for all the courses that will be returned at the end. The tricky bit is the for loop(s). You need to loop over the dictionary (like you did in the previous task) but, the list of courses from the value of the key/value pair cannot be added to your master list because you will have lists inside of a list. This means you need to loop over the list of courses for each teacher and then add each course individually into the master list. It results in having a for loop nested inside of another for loop like so:

def courses(a_dict):
    total_courses = []
    for key, value in a_dict.items():
        for course in value:
            total_courses.append(course)

    return total_courses

That was a bit long winded but I hope some of that made some sense - let me know if you have any questions! :)

hey can you help me when i need help

ok i follow you on github.com

hey how do i make a dict to return name

hey i need help

thank you rely again

hey