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

task 4/5 most_courses, throws Bummer Try again error

def most_courses(dict1): max_count = 0 teacher = "" for i in dict1.keys(): if max_count < len(dict1[i]): max_count = len(dict1[i]) teacher = i return teacher

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(dict1):
    return len(dict1.keys())

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

def courses(dict1):
    course_list = []
    for i in dict1.keys():
        for j in dict1[i]:
            course_list.append(j)
    return course_list        

def most_courses(dict1):
    max_count = 0
    teacher = ""
    for i in dict1.keys():
        if max_count < len(dict1[i]):
            max_count = len(dict1[i])
            teacher = i
    return teacher

2 Answers

Brandon Oakes
seal-mask
.a{fill-rule:evenodd;}techdegree
Brandon Oakes
Python Web Development Techdegree Student 11,501 Points

Task 4 out 5 works when I copy and past your code in. Check for indentation errors, or try and copy and paste what you posted in this question. Let me know if this does not work or if you were referring to task 5/5.

copy pasting the same code worked..I think it could have been the indentation error , because i have been testing the code in the workspace and then copying it over. I will keep this in mind for other tasks.Thanks!