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: 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
229,004 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.