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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Avi Tsipshtein](https://secure.gravatar.com/avatar/e00a31d0db77321ff45e76bd2aa138f0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Avi Tsipshtein
7,461 PointsLast challenge in "python collection" Can't get through stage one although I get the correct answer on my IDE
I tried this code to solve stage one:
import operator
my_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'], 'Kenneth Love': ['Python Basics', 'Python Collections'], 'Me Me': ['My Course']}
def most_classes():
x = max(my_dict.items(), key=operator.itemgetter(1))[0]
return x
most_classes()
I got the correct answer on my IDE but not on the challenge. So I went through other students question in the community tab and found this answer:
my_dict = {'Kenneth Love': ['Python Basics', 'Python Collections'], 'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Me Me': ['My Course']}
def most_classes(my_dict):
max_count = 0
busy_teacher = ''
for item in my_dict:
if len(my_dict[item]) > max_count:
max_count = len(my_dict[item])
busy_teacher = item
print(busy_teacher)
most_classes(my_dict)
But again no luck, I can't finish the first stage successfully. Help is much appreciated. Thanks!
4 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 Points
The challenge wants you to return the teacher with the most classes.
You won't need to print anything.
But you also might want to be sure you've finished checking them all before you return the top choice.
![Avi Tsipshtein](https://secure.gravatar.com/avatar/e00a31d0db77321ff45e76bd2aa138f0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Avi Tsipshtein
7,461 PointsThanks guys, indeed it was the the print statement that prevented me from finishing the first stage. Although I still don't understand why the first block of code didn't work. It has a return statement, It answers the question at hand and I quote: "should return the teacher with the most classes" and it does. At least on the IDE I work on.
![Avi Tsipshtein](https://secure.gravatar.com/avatar/e00a31d0db77321ff45e76bd2aa138f0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Avi Tsipshtein
7,461 PointsHi All,
for some reason when I submitting the second stage, I got an error that stage one is not passing anymore. I got back and found that if I click on 'check work' enough times, it will accept my code eventually. I don't know how the system is working in the background but it looks as if the system is calculating my answer differently every time. I can't move forward as stage one will be wrong and I will have to go back. How can solve this issue?
![Matthew Hill](https://uploads.teamtreehouse.com/production/profile-photos/6086742/micro_12931002_10100284130390087_5465800386731583958_n.jpg)
Matthew Hill
7,799 PointsHi Avi, can you post your amended code and the challenges that aren't passing?
![Avi Tsipshtein](https://secure.gravatar.com/avatar/e00a31d0db77321ff45e76bd2aa138f0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Avi Tsipshtein
7,461 PointsOk, so since my previous comment I managed to pass this stage but at the last stage I ran into a weird problem. I need to create a list of all the values in the dictionary. When I use append() I get this error: "You returned 8 courses, you should have returned 18." When I use insert() I get: "You returned 24 courses, you should have returned 18." Is there another way to add add items into a list without needing to specify an index (since the dictionary has no indexes)?
here is my code:
my_dict = {
'Kenneth Love': ['Python Basics', 'Python Collections'],
'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Me Me': ['My Course'],
'hiroshe': ['My Course'],
}
def most_classes(my_dict):
max_count = 0
busy_teacher = ' '
for item in sorted(my_dict, key=lambda item:len(my_dict[item]), reverse=True):
if len(my_dict[item]) > max_count:
max_count = len(my_dict[item])
busy_teacher = item
return busy_teacher
most_classes(my_dict)
def num_teachers():
teach_count = 0
for key in my_dict:
teach_count += 1
return teach_count
num_teachers()
def stats():
stats_list = []
for key, value in my_dict.items():
temp_list = [key, len(value)]
stats_list.append(temp_list)
return stats_list
stats()
course_list = []
def courses(my_dict):
for key, value in my_dict.items():
course_list.extend(value)
return course_list
courses(my_dict)
thanks!
Matthew Hill
7,799 PointsMatthew Hill
7,799 PointsThe one you found looks pretty legitimate, did you change the code to return the information requested in the challenge and in the format it asks it for? At the moment you're just printing the name of the teacher with the most classes.