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

What is the code?

What is the code?

teachers.py
def num_teachers(test2):
    return len(test2)
def num_courses(a_dict):
    a_list = []
    for key in a_dict:
    for item in key:
        if item not in a_list:
        a_list.append(item)
        else:
        continue
    return a_list

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

your indentation is off. the second for loop has to be indented a tab to be inside the first for loop. also the body of the if statement must be a tab in from the if. the else goes at the same level as the if but the rest goes one tab in (right).

"PLEASE PROVIDE SOLUTION FOR THIS"Wow, I just can't stump you! OK, two more to go. I think this one's my favorite, though. Create a function named most_courses that takes our good ol' teacher dictionary. most_courses should return the name of the teacher with the most courses. You might need to hold onto some sort of max count variable.

Joshua Dam
Joshua Dam
7,148 Points

You need to dig into the dictionary a little deeper. All you're pulling out of the dictionary are the lists. You need to get the values inside of the lists. You also don't need to include else: continue. The FOR statement will only run a certain number of times

Also, upon further inspection: using "for item in key:" is pulling out every character from just the keys. So it outputs this: ['A', 'n', 'd', 'r', 'e', 'w', ' ', 'C', 'h', 'a', 'l', 'k', 'y', 'K', 't', 'L', 'o', 'v']

Therefore, you need to use "for key, value" as shown below

for key, value in a_dict.items():
      for value in value:
krishnaprasad RS
PLUS
krishnaprasad RS
Courses Plus Student 413 Points
def most_courses(teacher_dict):
    for name, course in teacher_dict.items():
        if max(course):
            return name