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 trialAryan Monga
4,061 PointsA quiz question!
Wow, I just can't stump you! OK, two more to go. I think this one's my favorite, though. Create a function named most_courses that takes our good ol' teacher dictionary. most_courses should return the name of the teacher with the most courses. You might need to hold onto some sort of max count variable. What should I write next? With what should I compare the value? Help me please! THANKS! ;)
# 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.
#
# Your code goes below here.
def most_courses(g):
name=""
num_courses=0
for h in e.items():
name=h.keys()
num_courses= len(h.values)
def courses(e):
teachers_list=[]
for f in e.values():
teachers_list.extend(f)
return teachers_list
def num_teachers(a):
teachers=0
for b in a:
teachers = teachers+ 1
return teachers
def num_courses(c):
courses=0
for d in c.values():
courses = courses + len(d)
return courses
2 Answers
Steven Parker
231,269 PointsYou already asked this question a few hours ago.
Check that link and the answers already given there by Steve Hunter and Jon Mirow.
Matthew Schwer
Python Web Development Techdegree Student 975 Pointsdef most_courses(treehouse_teachers): highest_num = 0 teacher_most_classes = "" for key, value in treehouse_teachers.items(): if len(value) > highest_num: highest_num = len(value) teacher_most_classes = key return tearcher_most_classes
it says "Bummer: Couldn't find most_courses
" so I don't know why it won't even acknowledge the function's existence
Steven Parker
231,269 PointsIf there's an error in the definition, the function will remain undefined. Formatting is crucial to Python, so always use Markdown code formatting when posting code. Also, to reach the community as a whole always start a new question instead of adding one as an "answer" to another question.
Aryan Monga
4,061 PointsAryan Monga
4,061 PointsI know but I didn't understand it completely, could you write something additional for me?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsDidn't the answers posted by Steve and Jon help?
Aryan Monga
4,061 PointsAryan Monga
4,061 PointsThey did but I couldn't understand much, so I wrote the code as much as I knew! Check it out. Please help me to solve this! ;)
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou have a good start but you have a few issues:
for key, values in e.items():
"See if you can get it now.