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 trialJustin Carlson
12,755 Pointsfunction is supposed to take a list but when I put an arg in the function it asks where stats() is?
"Create a function named stats that takes a dictionary of teachers and returns a list of lists in the format [<name>, <number of classes>]."
all of these work but I can not figure out what they want for the last question?
def num_teachers(arg2):
return len(arg2)
def most_classes(arg1):
max_count = {}
for key in arg1:
max_count[key] = (len(arg1[key]))
sorted_list = sorted(max_count, key=max_count.get, reverse=True)
return sorted_list[0]
def stats():
return
7 Answers
Kenneth Love
Treehouse Guest TeacherJustin Carlson hmm, I'm not able to replicate that myself. I get "bummer" until i actually finish the function, but nothing about "where's stats()".
Justin Carlson
12,755 PointsOk so I retyped the whole thing this afternoon and rewrote how I was getting the lists and now.... drumroll.... it works. Not sure why I kept getting the stats() issue before but here is what I ended up with. THANK YOU for having a look and helping me out!
def stats(arg3):
teacherList = []
for key in arg3:
tempList = []
tempList.append(key)
tempList.append(len(arg3[key]))
teacherList.append(tempList)
return teacherList
Jacob Lewis
17,355 PointsThanks! I'd been hung up trying to get the length of the class number values, and it was just a silly syntax thing all along. Your answer helped me spot it.
Kenneth Love
Treehouse Guest TeacherI'll give you a dictionary like {"Kenneth Love" ["Python Basics", "Python Collections"], ...}
and I want back a list of lists like [["Kenneth Love", 2], ...]
Justin Carlson
12,755 Pointsyes I get that. but when I put an arg in the function like this:
def stats(arg4):
#some really cool code here
return answer
I get a red error at the top says "Bummer! Where's stats()
?" really frustrating :-) I am sure I have it right and if I feed a test dict into it in workspaces it works as expected and get lists back of teacher, number of classes.
Thank you for looking at this I am sorry to be a pain.....
MUZ140502 Natasha Hove
3,732 Pointsdef stats(tdict):
teacher_list = []
for key in my_dict:
my_list = []
my_list.append(key)
my_list.append(len(my_dict[key]))
teacher_list.append(my_list)
return teacher_list
I'm getting an error 'Where is stats()'....where am i getting it wrong??????
Kenneth Love
Treehouse Guest TeacherYou're getting tdict
but using my_dict
in the for loop. Since my_dict
doesn't exist, it throws a NameError
(which I currently have always sending back the "where is stats()" message). You fix your for loop, I'll fix the code challenge error. Deal?
Justin Carlson
12,755 PointsI'll just start all the way over and see if I just typed something in there wacky I cant see.... Thank you for looking. would be GREAT if errors were displayed in a console on tests instead of guessing sometimes. :-)
Kenneth Love
Treehouse Guest TeacherExcept for the last function, I used your exact code, so I'm not sure what would be causing it. If you don't get it to pass this next time through, send me an email with the code you're using and I'll take another look at it.
Agreed on the errors thing. We're constantly working on all parts of Treehouse and some things just take longer than others.
James Gill
Courses Plus Student 34,936 PointsJustin's error's happened to me too, on more than one occasion (and on this same exercise). I know that I'm just re-typing the same code--but hours or a day later, it works. Before that I get the "where's (function name)?"
Kenneth Love
Treehouse Guest TeacherI have had CCs act up on me occasionally where it'll see tabs as spaces and vice versa, so you get malfunctioning code. I've always "fixed" it by deleting my indentation and doing all of it over again with the space bar.
Not saying that's the problem you're both running into, but...maybe?
Jacob Lewis
17,355 PointsKenneth Love That sounds like the ticket. I've run into the same thing as James and Justin, and I've been able to resolve it by deleting spaces and re-entering them. I also think the space/tab confusion is what causes it.
Paulo Aguiar
14,120 PointsTheres definitely a bug with this question guys. Hitting submit twice would let me through ( with a correct answer )
Always bugging out. frustrating!