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.

Python

Steven Young
Steven Young
2,486 Points

Python dictionaries create a function named stats .... returns list of lists

here is my code:

def stats(t_d):
   master_list = []
   sub_list = []
   count = 0
  for key, value in t_d.items():
    for num in value:
      count+=1
    sub_list = [key, count]
    master_list.append(sub_list)
  return master_list

here is the message I'm getting: Bummer! didn't get the expected output. Got [[Andrew Chalky, 4], [Dave MacFarland, 5],[Kenneth Love, 7]] (etc.)

How can I fix?

Steven Young
Steven Young
2,486 Points

actually, more to the point; what did I do wrong? I have a list of lists with teacher name and number of classes, like the exercise asks for

1 Answer

Steven Young
Steven Young
2,486 Points

oh I think I know what the problem is, its counting every word in the classes given as its own class, but some classes have more than one word in them...