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 (Retired) Dictionaries Teacher Stats

My code works, but challenge gives me an error.

All the challenges worked up until the last one. when I run the code in my console it outputs the right number of courses, but the challenge tells me that I return 5 and expected 18. I corrected the dict to have 18 courses and ran it again, but it keeps telling me that i return 5. run it over my console and returns 18. any help will be appreciated.

teachers.py
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
my_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations', 'PHP',
                  ' Javascript', 'ajax', 'websites'],
'Kenneth Love': ['Python Basics', 'Python Collections', 'multimedia', 'marketing'],
'Oliver Stone': ['library', 'computer science', 'spanish','Espanol', 'other things', 'marbles', 'read']}


def most_classes(a):
    max_count = 0
    for key in a:
        if len(a[key]) > max_count:
            max_count = len(a[key])
            max_name = key
    print(max_name)
    return max_name

most_classes(my_dict)

def num_teachers(a):
  return len(a)

num_teachers(my_dict)

def stats(a):
    the_list = []
    for key in a:
        listitem = [key,len(a[key])]
        the_list.append(listitem)
    print(the_list)
    return the_list

stats(my_dict)

def courses(a):
    course_list = []
    for value in a.values():
        course_list.append(value)
    print(course_list)
    return course_list

courses(my_dict)

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Using .append() puts whatever value is into your course_list variable. So if value is a list, your list now has a list inside of it. You'd end up with something like [['a', 'b', 'c'], ['d', 'e'], ['f']] instead of the ['a', 'b', 'c', 'd', 'e', 'f'] that the challenge is expecting. You want to use .extend().

Thank you very much!