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 trialeodell
26,386 Pointsteacher? or teachers? and course? or courses? Does it matter? and please help me understand why.......
Challenge Task 5 of 5 It's official: you're awesome at Python dictionaries! One last task and then you can take a well-deserved break!
In this last challenge, I want you to create a function named stats and it'll take our teacher dictionary as its only argument.
stats should return a list of lists where the first item in each inner list is the teacher's name and the second item is the number of courses that teacher has. For example, it might return: [["Kenneth Love", 5], ["Craig Dennis", 10]]
# 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(teachers):
total = 0
for value in teachers.values():
for course in value:
total += 1
return total
def courses(teachers):
result = []
for courses in teachers.values():
result += courses
return result
def most_courses(teachers):
max_count = 0
professors = ""
for teacher, course_list in teachers.items():
if len(course_list) > max_count:
max_count = len(course_list)
professors = teacher
return professors
def stats(teachers):
name_list = []
for teacher, course in teachers.items():
name_list.append([teacher, len(course)])
return name_list
Dane Parchment
Treehouse Moderator 11,077 PointsCan you please rephrase your question? I am having trouble understanding what it is you are asking for help with.
1 Answer
Alexander Besse
Full Stack JavaScript Techdegree Graduate 35,115 PointsI believe what you're trying to ask is if the name of a variable matters during the execution of a script. Yes and no, the variable can be named whatever you want - as long as it referenced properly. If it's not referenced correctly, you'll get a NameError exception.
Hope this helps, happy coding!
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsWhat is your question?