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 Python Collections (Retired) Dictionaries Teacher Stats

Shane Wilkinson
Shane Wilkinson
1,148 Points

Write a function named classes that takes a dictionary of teachers

I don't know what I'm doing wrong here. I have run the script through terminal on my mac and am able to get the expected results. However, when I try to run it through the Recheck Work function, I either get 'It looks like Task 1 is no longer passing' or 'Bummer, Try Again'

Any help would be appreciated so I can get past this step!

teachers.py
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
{'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Kenneth Love': ['Python Basics', 'Python Collections']}

def most_classes(dictionary):
  classcount = 0
  classnumbers = {}
  for key in dictionary:
    classnumbers[key] = len(dictionary[key])
    if classnumbers[key] > classcount:
      busy_teacher = key
      classcount = classnumbers[key]  
  return busy_teacher
most_classes(list)
def num_teachers(dictionary):
  count = 0
  for key in dictionary:
    count += 1
  return count
num_teachers(list)
def stats(dictionary):
  list1 = []
  for key in dictionary:
    templist = [key, len(dictionary[key])]
    list1.append(templist)
  return list1
stats(list)                 
def courses(dictionary):
  courselist = []
  for key in dictionary:
    templist = dictionary[key]
    for item in templist
      courselist.append(item)
  return courselist 
courses(list)

2 Answers

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

EDIT: You forgot a colon ':' after a for instruction. The "if item not in courselist" was not neccesary after all but it doesnt hurt.

def courses(dictionary):
    courselist = []
    for key in dictionary:
        templist = dictionary[key]
        for item in templist:    #<-------------- here
            if item not in courselist:
                courselist.append(item)
    return courselist 
Shane Wilkinson
Shane Wilkinson
1,148 Points

Unfortunately I still get 'Bummer, Try Again!'

I've tried just about every permutation from all the other answers on questions about this challenge but I keep getting 'Try again' which isn't very helpful to debug

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

I found the error, you forgot a colon, I edited the answer.

Shane Wilkinson
Shane Wilkinson
1,148 Points

Yeah, I caught that when I initially ran the code (as I was thrown a syntax error) but even with the fix, I still get 'Try Again!'

Did you try changing the name of the function to "classes"?

Shane Wilkinson
Shane Wilkinson
1,148 Points

Just did... threw back name 'courses' is not defined. Any other ideas? Thanks for the suggestion!

Ah, sorry. I was just going off the title of your question. When I try your code with just the most_classes function in it it runs fine, but if I add something like the line right after it "most_classes(list)" I get an error. I'm not sure what you're doing that for.

Shane Wilkinson
Shane Wilkinson
1,148 Points

I figured it out... The terminal didn't like my dictionary being named 'list'...Thank you for your answer, it got me on the right track. Dumb mistake