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

need help

need help Great work! OK, you're doing great so I'll keep increasing the difficulty. For this step, make another new function named courses that will, again, take the dictionary of teachers and courses. courses, though, should return a single list of all of the available courses in the dictionary. No teachers, just course names!

teacher_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
                'Kenneth Love': ['python Basics', 'Python Collections']}

def most_classes(teachers):
  top_teacher = ''
  max_count = 0

  for teacher, classes in teachers.items():
    if len(classes) > max_count:
      top_teacher = teacher
      max_count = len(classes)

  return top_teacher

def num_teachers(a_dict):
  count = 0
  for key in a_dict:
    count += 1
  return count

def stats(a_dict):
  a_list = []
  for key in a_dict:
    a_list.append([key, (len(a_dict[key]))])
  return a_list

def num_courses(courses):
    return sum(len(v) for v in courses.values())

Moderator edited: Added markdown so that the code will be rendered properly in the forums.

Jimmy Holway
Jimmy Holway
10,703 Points

You will get help more often if you take the time to format your question with Markdown so it's easier for people to read your question and understand it.

Check out the Markdown Cheatsheet link thats right under the post box you use to write your questions for a quick reference on how to do that.

Steven Parker
Steven Parker
231,110 Points

I agree with Jimmy, but I would add that it's also good to provide a link to the course page you are working with. The combination of the course reference and correctly formatted code help greatly in analyzing your issue.

sorry it said 120 max characters.But every time i replace this bit of code def num_courses(courses): return sum(len(v) for v in courses.values()) with something else it say's go to task two!

14 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You didn't write any code yourself, searched for an answer, and then gave yourself "Best Answer" because you passed the challenge. Does that sum it up? If you just want badges, you could hire a designer to make some for you for less than what you're paying monthly for Treehouse, you know.

If you want to learn, though, you might just have to try.

To be honest with you Isaac, I completely understand why you Googled for answers. I've been a Full time Django/Python Developer for two years, and I still struggle while solving problems on the TreeHouse code challenges. This is because the debugger provided by TreeHouse is completely useless. I have no idea why the full stack trace isn't provided, instead when you error you get "Bummer" or in the slight chance the instructor wrote their own and that rarely gives any insight into the errors.

For community leaders to be questioning you about Googling the answer is slightly disheartening as most of a developers job is to review other peoples code and attempt to make it work for your solution. Yes, in this instance you are trying to learn, and copying and pasting only cheats yourself. However, it could have been much more constructive.

Steven Parker
Steven Parker
231,110 Points

Gotta wonder, after nearly 2 years, what prompted you to revisit this old question today?

I mean doesn't that speak volumes, that coworkers and I often think about this post when we go on TreeHouse. I wouldn't exactly say the actions that have been demonstrated on this forum post have been reflective of a healthy learning environment.

If you refer to TreeHouse's companies values found here: https://blog.teamtreehouse.com/values

"Never stop working hard or being nice. By doing so as individuals we are stronger as a team."

I would not suggest we are working stronger as a team here.

Michael Hulet
Michael Hulet
47,913 Points

I'm legit curious: Who was bashing someone about googling anything? Only 1 moderator commented here, and I don't understand what you think she did to attack anyone

Hi Michael,

Thank you for your reply. My concern here is that nobody was working towards finding a solution, rather everyone was fixated on the copying and pasting of a solution. More specifically comments about hiring a designer to receive badges would be a better use of his time, and that he just simply isn't "trying hard enough".

Maybe Isaac is just having a difficult time grasping the concept, so he searched the internet as most Devs do to find a solution.

Steven Parker
Steven Parker
231,110 Points

Kenneth's reaction was unusually strong here but there could be a context I'm not aware of involving other interactions with the same student. But otherwise, the answers and comments here seem supportive of a positive learning experience, so I'm not sure what's causing you to have such a different (and lasting!) impression.

And in my very first post in answer to this question, I made several suggestions about a possible strategy for resolving the issue. I believe that constitutes "working towards finding a solution".

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi, Kyle Hartigan ! It was never my intention to "bash" anyone for Googling. I do it all the time :smiley: But there may be a misunderstanding about what I was saying and it has a lot to do with the context at the time. At the time of this post, the first Google result lead back to a previous version of the challenge that would have resulted in a solution that didn't work because the challenge was changed. What we saw in the code posted here were answers further down the challenge but missing the intermediary part. I left an open invitation to the student to post the code so that I could help. I love to help! :sparkles: But it's incredibly hard to do without first knowing what they've tried.

Michael Hulet
Michael Hulet
47,913 Points

I agree, this thread probably could've turned out better, though it also seems to be missing some context that was here before. Most of the comments seem to be about Google because there seems to be no other information to go off of. There wasn't a question, just a code dump. It seems that OP had initially marked themselves as having the best answer (though it's been removed), which gives you a bump in your total points, which made the whole thing look like a bit of a points-grab and not a learning attempt. I'm not defending what Ken said here, or implying OP wasn't here to do anything but learn, but it's important to have that context for historical purposes. If you'd email help@teamtreehouse.com and let them know about the error messages, it'll add your vote on where they should be in their internal priorities about fixing them. You can also let them know about this thread, too, and they can decide out what the right thing to do is

Thank you Michael.

Rob Allessi
Rob Allessi
8,600 Points

Kyle Hartigan

Thanks for bringing up your concerns on this. I sincerely appreciate it. I'm sorry to hear that this is a standout post for you and your colleagues. I feel that over the past decade, there's a wealth of information and evidence that Treehouse works as a team and we do what we can to help students out as often as we possibly can. There are thousands of posts where this has been demonstrated and are far more representative of Treehouse than this post is.

With that being said, I'd like to add a bit of context to this situation. At the time, the student was slamming the forum with a new topic related to this — over 10 posts in 2 hours, where help was being provided and ultimately ignored, those posts were eventually deleted and this remained as the main post. Regardless, Kenneth's comment was unusually out of character and what I can only assume was out of frustration.

Personally, and this is speaking purely on behalf of myself, I believe googling an answer is totally fine, and expected of any developer, but only as long as there is some intent to actually attempting to understand the answer. We even have a short video on this done by Craig where we ask the question "What do you do when you don't know something?" and the correct answer is "We Google it!" but it's under the assumption that you're googling it to also better understand it.

Thank you Rob!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Isaac! I'm inclined to agree with Steven Parker on this. You're on step 3 which requires you to make a function named courses. However, this function appears nowhere in the code that you've posted. I'd be interested to know what you've tried for the courses function that's failing so as to better assist you in your learning experience.

That being said, while Googling to get information is great, I'd be wary of attempts to cut/paste answers from the forums without understanding what's happening. There are a couple of reasons for this. First, if you don't understand it, you'll never be able to reproduce the logic. Secondly, these challenges are altered and changed frequently. Code that passed yesterday might not pass today. Instructors can and very often do change instructions, variable names, and even the expected output of the code in the challenge.

I look forward to seeing the courses function that you've tried!

Hope this helps! :sparkles:

edited for additional note

I took the liberty of adding some markdown to your code in your question so that it will render properly on the forums. At the bottom of the "Add an Answer" section, you can find a Markdown Cheatsheet which explains how to properly post code so that other students in the Community can help you more effectively. :smiley:

Steven Parker
Steven Parker
231,110 Points

I don't see your "courses" function.

Have you started working on that one yet? But oddly, you have some code that seems to be for even later tasks. You didn't just paste in some code you found somewhere, right?

But one way to write courses would be to loop through all the items in the dictionary, and add each separate course list to a master one that you will return after the loop finishes. This might be a good place to use the extend function.

well when i couldn't figure it out.I googled it and yes i did paste some code in.

Steven Parker
Steven Parker
231,110 Points

Just looking at someone's solution can be useful, but always re-create it and be sure you understand what each statement is doing. And, as in this case, there's always a chance that the other code might be incomplete or incorrect. It can be a lot harder to fix someone else's mistakes than your own!

seong lee
seong lee
4,503 Points

dude be quiet listen to the people that's actually trying to help you. Not everything that you google will be right, "if you didn't know". So why don't you stop spamming the chat with, "I googled it second" and actually follow the directions Steven parker tells you and what the moderator tells you tell you

seong lee i'm desperate to get past this challenge i'm not fighting you

seong lee
seong lee
4,503 Points

okay, to do that you need to follow the directions steven parker is telling you, and the moderator, I know it can be a struggle and I understand your feelings, and try no matter how hard it gets.

i googled Great work! OK, you're doing great so I'll keep increasing the difficulty. For this step, make another new function named courses that will, again, take the dictionary of teachers and courses. courses, though, should return a single list of all of the available courses in the dictionary. No teachers, just course names!

Steven Parker
Steven Parker
231,110 Points

I understand what you did, but as I said, you have to be cautious of bugs other people posted.

When your frustration calms down, would you mind deleting all the spurious answers added to this question?

but steven i googled it second

not excited more like frustrated

but i said i googled it "second"

but i googled the answer second

but i googled it second

if you know the answer please tell me

i get it it's just i don't know the answer!!!!