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 trialDavid Chac贸n
1,086 PointsNeed a helping hand/shove on step 4/5 of teachers.py
Hey community! I've been getting GREAT help so far but alas, my python logic and knowledge is a little stumped.
Not sure what I'm doing or not doing correct. I know it is in the 'if' statement but can't figure it out. Help would be great, not direct answers please!
# 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(teachers):
count = 0
for teacher in teachers:
count += 1
return count
def num_courses(courses):
count = 0
for i in courses:
count += len(courses[i])
return count
def courses(courses):
count = []
for i in courses:
count += courses[i]
return count
def most_courses(teacher):
leader = 0
teacherMost = ""
for i in teacher:
if i in teacher[i] > leader:
leader = len(teacher[i])
teacherMost = teacher.value()
else:
continue
return teacherMost
2 Answers
Kurt Maurer
16,725 PointsHey David,
Great job so far. In your for loop, i
is referencing the key in the dictionary.
def most_courses(teacher):
leader = 0
teacherMost = ""
for i in teacher:
# if i in teacher[i] > leader:
if len(teacher[i]) > leader:
leader = len(teacher[i])
teacherMost = i # Since i is the key, don't need teacher.value()
else:
continue
return teacherMost
Also, another way to do it:
def most_courses(teacher):
leader = 0
teacherMost = ""
for key, value in teacher.items():
if len(value) > leader:
leader = len(value)
teacherMost = key
else:
continue
return teacherMost
Both passed the challenge, hope this helps!
Matthew Gilbert
9,817 PointsI keep getting this Error: Bummer: Didn't get the right teacher name!
Kurt Maurer
16,725 PointsKurt Maurer
16,725 PointsAlso worth noting:
This is implicit and not required for your code to work. You can delete it if you want.