Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Denis Frunz
15,929 PointsHow can I count items in list inside of dictonary?
I have no idea how I can do this, work all day long and still nothing....
# 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 (dict_teacher):
count = 0
for key in dict_teacher.keys():
count += 1
return count
def num_courses (dict_teacher):
count = 0
for key in dict_teacher.values():
count += 1
return count
3 Answers

Steven Parker
221,292 PointsIt looks like you're trying to use almost the exact same code that counts the teachers to count the courses.
But to count the courses, you'll need to get a count of courses for each teacher and then add those all up together.

Denis Frunz
15,929 Pointsthis is what I did ,it works well in workspace but in a challenge I keep run into "Bummer: Try again!"
# 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(teacher_dict):
count = 0
for key in teacher_dict.keys():
count +=1
return count
def num_courses(teacher_dict):
count = 0
for value in teacher_dict.values():
for i in value:
count +=1
return count

Steven Parker
221,292 PointsThat looks OK to me. So I pasted it directly into the challenge and it passed task 2!
Try again?

Denis Frunz
15,929 PointsWhen I reload a page it worked )
Denis Frunz
15,929 PointsDenis Frunz
15,929 Pointsfirst function counts how many teachers we have, second function mustt count how many courses we have in total, so my functions counts in total 3 ccourses that'snot right I need to understand how I can count items in these lists
Steven Parker
221,292 PointsSteven Parker
221,292 PointsThe code you have now counts the entire list of courses for each teacher as one thing. So one approach you might use is to have another loop inside that one count each course in the list.
Besides counting the courses one at a time, another choice might be to use the length of the list.