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 trialnewpal
1,717 Pointswhat is wrong with my code?
def courses(dict): available_courses = [] for value in dict.values(): available_courses.append(", ".join(value)) return available_courses
# 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
1 Answer
Steven Parker
231,236 PointsThe courses returned should be individual items, but this code will return strings of comma-separated course names.
newpal
1,717 PointsThank you Steven. Any ideas on how to make my code return individual items?
Steven Parker
231,236 PointsYou won't need to "join" anything. The entire purpose of that function is to convert individual items into a string.
newpal
1,717 PointsBut if I do not use "join", my code returns list inside a list.
Steven Parker
231,236 PointsIt does that if you use "append". But there's another method that combines lists differently.
newpal
1,717 PointsYes! it is the .extend() method! :) Thank you Steven!
newpal
1,717 Pointsnewpal
1,717 PointsCould you please provide the answer to this code challenge?