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 trial

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...