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 trialHunter G
6,612 PointsTeacher Stats Challenge. Why do you assign teacher variable to "" ?
Below is the correct code for Task 1 of this Challenge which I resourced from another forum post. My question though is why do you assign teacher to the double quotes? What exactly is that doing?
# 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(my_dict):
count = 0
teacher = ""
for key in my_dict:
if (len(my_dict[key]) > count):
count = len(my_dict[key])
teacher = key
return teacher
1 Answer
David Diehr
16,457 PointsSo I just checked, and this code passes the challenge without that line. This just establishes the variable as an empty string. Sometimes people just establish empty variables at the beginning of a function to help guide their thinking about how they're gonna write the function. In some cases you establish an empty string so you can concatenate that variable later on even if it's empty (obviously, not the case here) just like you might establish an empty array or object so you can append it later.
Hunter G
6,612 PointsHunter G
6,612 PointsAhh, an empty string. Thank makes much sense! Thank you for your explanation David!! :)