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 trialAndrew Bickham
1,461 Pointsdef num_teacher
im only on task one but i don't see why i can clear this first phase???
# 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.
#
def nun_teachers(string):
count = dict(len(string.key()))
return count
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsYou are on the right path. Three items to correct:
- typo in function name, it's not "nun_teachers"
- the method of getting the keys is
key
s, plural - creating a
dict
isn't necessary. The challenge wants the integer result.
Post back if you need more help. Good luck!!
Andrew Bickham
1,461 Pointsdef num_courses(teachers):
number = []
for value in teachers.values():
count = len((teachers.values())
number[count] = teachers.sum(count)
return number
I know im coming to you for every little detail but when I do it on my own workspace, the error I keep getting is a syntax error for "number[count] = teachers.sum(count)", am i writing it incorrectly or is there some other issue?
Chris Freeman
Treehouse Moderator 68,441 PointsThe syntax error is coming from the previous line due to missing closing paren.
In the line you mention, the teachers
dictionary passed in does not have a sum
method. So this too will trigger an error.
The challenge is looking for the total number of courses. This would be the sum of all the count
values and not a list of the count
values.
Andrew Bickham
1,461 Pointsso instead of using the sum method the count method would be the way to go, if im only looking for the total number of courses and not the complete total
Chris Freeman
Treehouse Moderator 68,441 PointsLet's look at the ways you can get information from the teachers
dictionary:
-
teachers.values()
is a listing of the dictionary values: the course lists -
teachers.keys()
is a listing of the dictionary keys: the teacher's names -
for value in teachers.values(): len(value)
will give you the number of courses for a single teacher - add up all of the
len(value)
to get the total courses
Andrew Bickham
1,461 Pointsthank you i was able to get it on to phase three, fair warning they'll probably be some more questions
Andrew Bickham
1,461 PointsAndrew Bickham
1,461 Pointsevery detail counts, thank you!
Andrew Bickham
1,461 PointsAndrew Bickham
1,461 Pointsall im getting is bummer try again for phase two is there a certain detail im just not seeing?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsYou are close again. The code
string.values()
returns an iterable of the dictionary values. Thecount
should be a sum of each valueβs length. A loop likefor value in string.values():
would work.Also, better to name the function parameter something other than βstringβ since itβs a
dict
passed in. Tryteachers
.