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

Afloarei Andrei
Afloarei Andrei
5,163 Points

Why I get the Bummer! if the function is returning a list with all the courses?

I don't understand why I get the "Bummer! Didn't get all...." I tried to return that list in every way I know but I still get that Bummer!

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.
dictionary = {'Andrew Chalkley': ['jQiery Basics', 'Node.js Basics'], 'Kennetg Love': ['Python Basics', 'Python Collections']}
key_list = []
value_list = []

def num_teachers(dictionary):
    for key in dictionary.keys():
        key_list.append(key)
    return len(key_list)

def num_courses(teachers_dict):
    count = 0
    for teacher in teachers_dict:
        count = count + len(teachers_dict[teacher])
    return count

def courses(dictionary):
    for value in dictionary.values():
        value_list.append(value[0])
        value_list.append(value[1])
    return value_list
print(courses(dictionary))

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

There are two errors.

  • To get the first to challenges to pass, move the key_list and value_list initialization inside of their respective functions.
  • When appending the teachers courses, keep in mind that there may be any number of courses and not precisely two.

Post back if you need more help. Good luck!!

Afloarei Andrei
Afloarei Andrei
5,163 Points

I managed to pass this challenge and I found out that value[0] was returning the first item from bought lists and value[1] the second item from bought lists. Thanks :)