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 trialMarzoog AlGhazwi
15,796 PointsCan anyone help me with this !!
I couldn't find a way to return the name of the teacher with most courses How can I make the comparison and return the teacher name?
# 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.
import itertools
def num_teachers(dictarg):
return len(dictarg.keys())
def num_courses(dictarg):
re_list = dictarg.values()
re_list = itertools.chain(*re_list)
return len(list(re_list))
def courses(dictarg):
re_list = dictarg.values()
chain = itertools.chain(*re_list)
return list(chain)
def most_courses(dictarg):
for key, value in dictarg.items():
tup = key,len(list(value))
1 Answer
billy mercier
6,259 PointsLoop through the number of teachers, add the len(keys) they have, then the if statement will be looped through to find the highest len(keys). The key point in this exercise is to compare both teachers len(keys).
def most_courses(courses):
d = []
winner = ''
for key, value in courses.items():
d.append(len(value))
if len(value) >= len(d):
winner = key
return winner