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 trialNick Smith
6,688 PointsLocal Computer vs Workspace
So I have two sets of code, one that passes on treehouse, but fails on my local computer and one that passes on my local computer and fails on workspace.
I am wondering if anyone knows why this is happening?
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
"""
So I have two sets of code, one that passes on treehouse,
but fails on my local computer and one that passes
on my local computer and fails on workspace.
I am wondering if anyone knows why this is happening?"""
#This passes on TREEHOUSE but FAILS on LOCAL:
def most_classes(dicts):
most_class = ""
max_count = 0
for teacher in dicts:
if len(dicts[teacher]) > max_count:
max_count = len(dicts[teacher])
most_class = teacher
return most_class most_classes(teachers)
#This passes on LOCAL but FAILS on TREEHOUSE:
def most_classes(dictionaries):
max_count = 0
busiest_teacher = None
for teacher in dictionaries:
for key in teacher:
if (len(teacher[key])) >= max_count:
max_count = len(teacher[key])
busiest_teacher = key
return busiest_teacher
1 Answer
Steven Parker
231,269 PointsThe first version has a syntax error in the return line (I have no idea how that got by the challenge):
return most_class most_classes(teachers) # original line
return most_class # fixed
The second version may run on your machine, but it does something very different from what the challenge asks for. It has a second loop inside the first one that examines the letters of the teacher's name instead of the number of classes. But I'm also amazed that one runs since it tries to use a letter as an index for a string.