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 trialAbdillah Hasny
Courses Plus Student 3,886 PointsNeed to return 18 from 5 classes sample input ( Task 4 )
I got this error Bummer! You returned 5 courses, you should have returned 18.
how to returned 18 from all the course offered by teacher just 5
# 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(dicts):
tmp = 0
hasil = ""
for x in dicts:
if tmp == 0:
tmp = len(dicts[x])
elif tmp < len(dicts[x]):
tmp = len(dicts[x])
if len(dicts[x]) == tmp:
hasil = x
return hasil
def num_teachers(dicts):
total = 0
for x in dicts:
total += 1
return total
def stats(dicts):
hasil = []
for x in dicts:
hasil.append([x, len(dicts[x])])
return hasil
def courses(dicts):
hasil = []
for x in dicts:
hasil.append(dicts[x])
return hasil
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou are Very close. In courses
, each "x" in dicts is a list. There is one for each teacher. Using append()
will add each of these lists to hasil
as a single item, thus creating a list of five lists.
What you need is to extend hasil
with the contents of each list using extend()
:
def courses(dicts):
hasil = []
for x in dicts:
hasil.extend(dicts[x]) #< extend instead of append
return hasil
Abdillah Hasny
Courses Plus Student 3,886 PointsAbdillah Hasny
Courses Plus Student 3,886 Pointsthanks again , iget the idea :)