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 trialGregory James
6,537 Pointscourses
I have worked on this problem a while and it is actually the reason why I almost quit coding. I tried learning other things but couldn't let go of allowing this code to beat me and make me quit. If I don't understand this, should I go learn the fundamentals again. I just need some guidance. Also if I can't even do this is there even a reason for me to try the next part of the challenge. Again, should I just go back to the beginning of the course.? What should I review if I don't understand this?
# 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.
#
def num_teachers(dict):
return int(len(dict))
def num_courses(dict):
courses = 0
for x in dict:
courses += int(len(dict[x]))
return courses
#return a single list of all available courses is the dictionary
#No teachers, just courses names
def courses(dict):
for x in dict:
print(list(dict[x])
2 Answers
Steven Parker
231,275 PointsMichael's advice is good, though I might rephrase the part about the objective. Remember that you need to return the courses in a list, and you won't need to "print" anything. The previous task might serve as a model for this one, just accumulate a list of courses instead of adding up a count of them.
This 5-part challenge is one that is frequently asked about, you may find that the ones that come later in the course actually seem less difficult.
It can often be helpful to see other questions asked about the same issue. This can easily be done by clicking on the "breadcrumbs" at the top of this page, which in this case would be the words Teacher Stats (or the ones right in this sentence) to see a list of them. There have been quite a variety of different ways used to solve these by students over the years, reading some of them taught me a thing or two.
Michael Moniz
7,519 PointsHi Gregor, what i can see in your code is that you are missing a ")" on line 20 and your print statement isn't indented, after you correct those little syntax errors, your code should work :) But that's not what the challenge is asking for, you should return a sing list with all the courses but you are printing several lists.
Right now you are printing a list for every loop, but it should be an easy fix, try it for your self, if you need help just ask!
Never give up! I know it's hard on the beginning but if you keep going you will get better and better and you will be able to understand everything much better!