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

Task 4: Checked independently--will get back teacher with max count of classes!!

Please let me know what is up. I checked this independently and I consistently get the correct count of teachers as I vary the amount of classes per teachers in my dictionary.

# 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):
    list1 = (list(dict1.keys()))

def num_courses(dict1):

    list2 = (list(dict1.values())) 
    flat_list = []
    for sublist in list2:
        for item in sublist:

def courses(dict1):

    list2 = (list(dict1.values())) 
    flat_list = []
    for sublist in list2:
        for item in sublist:

def most_courses(dict1):

    list4 = list(dict1.items()) 
    max_count = []
    len_val_iterable = 0

    i = 0
    for tup in list4:
        tup = list4[i:i+1]
        tup_pop = tup.pop()
        tup_val = list(tup_pop[1:])
        flat_list = []
        for sublist in tup_val:
            for item in sublist:
        len_val = len(flat_list)

        if len_val > len_val_iterable:
           len_val_iterable = len_val
           max_count = tup_pop[0:1]
        elif len_val == len_val_iterable:
           max_count = max_count + tup_pop[0:1]
        i +=1

2 Answers

Steven Parker
Steven Parker
221,295 Points

I'd be curious to know more about the independent checking procedure. The "most_courses" function doesn't seem to return anything at all.

Also, you say you "get the correct count of teachers", but the instructions say that this function "should return the name of the teacher with the most courses."

When I sent original question to you I forgot to add "return(max_count)". It was since added and it still did not compile.

I use spyder 3.2.6 and yes it does return the teacher(s) name(s). 100% absolutely. I am not a moron. perhaps you are using the buggy compilers that treehouse puts outs.