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 wrong with my code?

def courses(dict): available_courses = [] for value in dict.values(): available_courses.append(", ".join(value)) return available_courses

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.
def num_teachers(dict):
    count = 0
    for key in dict.keys():
        count += 1
    return count

def num_courses(dict):
    count = 0
    for value in dict.values():
        count += len(value)
    return count

def courses(dict):
    available_courses = []
    for value in dict.values():
        available_courses.append(", ".join(value))
    return available_courses

Could you please provide the answer to this code challenge?

1 Answer

Steven Parker
Steven Parker
231,269 Points

The courses returned should be individual items, but this code will return strings of comma-separated course names.

Thank you Steven. Any ideas on how to make my code return individual items?

Steven Parker
Steven Parker
231,269 Points

You won't need to "join" anything. The entire purpose of that function is to convert individual items into a string.

But if I do not use "join", my code returns list inside a list.

Steven Parker
Steven Parker
231,269 Points

It does that if you use "append". But there's another method that combines lists differently.

Yes! it is the .extend() method! :) Thank you Steven!