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 trialDeniz Kahriman
8,538 PointsWhat am I doing wrong here? Creating a new list from a list: [teachers, # of classes]
I got stuck in the last part of the challenge :/
# 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(dictionary):
count = len(dictionary.values())
return count
def num_courses(teachers_courses):
list_courses = []
for courses in teachers_courses.values():
list_courses.extend(courses)
return len(list_courses)
def courses(dictionary):
single_list = []
for courses in dictionary.values():
single_list.extend(courses)
return single_list
def most_courses(dictionary):
max_value = 1
for key in dictionary:
if len(dictionary[key]) > max_value:
max_value = len(dictionary[key])
max_key = key
return max_key
def stats(dictionary):
master_list = []
for keys, values in dictionary.items():
master_list.append([key, len(value)])
return master_list
1 Answer
Steven Parker
231,248 PointsYour variable names aren't consistent.
In your loop, your iteration variables are keys and values (both plural), but when you use them to append to your master list you refer to key and value (both singular). Pick one set or the other and use the same names in the assignment and the loop and you'll pass.
Deniz Kahriman
8,538 PointsDeniz Kahriman
8,538 PointsThanks, Steven!!