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 trialChris Edwards
8,163 PointsThe code I have entered works perfect on my mac. Not sure why its failing on your system
The code I have entered works perfect on my mac. Not sure why its failing on your system
def stats(courses): course_count = 0 course_only_list = [] total_courses = {} total_courses_list = [] for teacher in courses: total_courses[teacher] = 0 course_list = courses[teacher] for course in course_list: total_courses[teacher] += 1 for k, v in total_courses.items(): total_courses_list.append([k,v]) return total_courses_list
# 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):
teacher_count = 0
for teacher in teachers:
teacher_count +=1
return teacher_count
def num_courses(courses):
course_count = 0
for teacher in courses:
course_list = courses[teacher]
for course in course_list:
print(course)
course_count +=1
return course_count
def courses(courses):
course_count = 0
course_only_list = []
for teacher in courses:
course_list = courses[teacher]
for course in course_list:
course_only_list.append(course)
return course_only_list
def stats(courses):
course_count = 0
course_only_list = []
total_courses = {}
total_courses_list = []
for teacher in courses:
total_courses[teacher] = 0
course_list = courses[teacher]
for course in course_list:
total_courses[teacher] += 1
for k, v in total_courses.items():
total_courses_list.append([k,v])
return total_courses_list
1 Answer
Shreyas Papinwar
2,371 Pointshey try to change the last function , and try harder to make your functions as small as possible.
def stats(courses):
dist = {}
for course in courses:
dist[course] = len(courses[course])
return dist
and you don't have the function most_courses, please next time try to ask more accurate question.
Chris Edwards
8,163 PointsChris Edwards
8,163 PointsYour code doesn't work either. If you want me to write SMALL code then your class should teach how to write the function before you ask me to write it.