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 trialRobert Rajczyk
3,699 PointsChallenge Task 3/4 - "most_classes" excercise
Hello,
I don't understand why my code doesn't work. Can someone help me?
# 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.
def most_classes(teachers):
maxNum = 0
name = ''
for k,v in teachers.items():
if len(v) > maxNum:
name = k
maxNum = len(v)
return name
def num_teachers(teachers):
count = 0
for k,v in teachers.items():
count += 1
return count
def stats(teachers):
name = []
for k,v in teachers.items():
name.append(k)
name.append(len(v))
return name
1 Answer
Robert Rajczyk
3,699 PointsHello,
Sorry for problem. I already found solution:
def stats(teachers): name = []
for k,v in teachers.items(): list = [] list.append(k) list.append(len(v)) name.append(list) return name