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 trialAshikur Rahman
129 PointsCan't pass this step.
Can't build up logic for this step. Code attached. Anything helpful from you will be appreciate
# 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 num_teachers(arg):
return(len(arg))
def num_courses(arg):
total = 0
list = []
for course in arg:
list.append(len(arg[course]))
total = sum(list)
return(total)
def courses(c):
teachcourse=[]
for teach in c.values():
teachcourse.extend(teach)
return teachcourse
def most_courses():
def most_courses(arg):
max_count = 0
name = ""
for value in arg.items():
teacher = arg.keys()
courses = arg.values()
max_count = max(courses)
if len(courses) > len(max_count):
name = teacher
return name
1 Answer
รyvind Andreassen
16,839 PointsHi,
When I get stuck, I print out variables and check if they contain what I think they are suppose to contain.
for value in arg.items():
teacher = arg.keys()
courses = arg.values()
max_count = max(courses)
These three variables don't hold the values that you want, rather returning
teacher returns: dict_keys(['Andrew Chalkley', 'Kenneth Love'])
courses returns: dict_values([['jQuery Basics', 'Node.js Basics'], ['Python Basics', 'Python Collections']])
max_count returns: ['jQuery Basics', 'Node.js Basics']
I would suggest that you change the loop to the following, and consider where your placing the assignment of max_count in the loop.
for key, value in arg.items():
teacher = key
courses = value
There are plenty of threads that will give you the answer, but I hope this helps you to figure out the solution. Just a heads up, consider the wording of the challenge. It asks you to return the name, not the names.