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!

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

Please Tell me what's wrong with this python code?

Hi, please can someone help me with this code?

# 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.
teachers_Classes = {"Jason Seifer" : ["Ruby Foundations", "Ruby on Rails Forms", "Technology Foundations"],
                  "Kenneth Love" : ["Python Basics", "Python Collections"]}
def most_classes:
  if "Jason Seifer".len() in teachers_Classes >= "Kenneth Love".len() in teachers_Classes:
    return teachers_Classes("Jason Seifer")
    return teachers_Classes("Kenneth Love")

1 Answer

Ken Alger
Ken Alger
Treehouse Teacher


Let's take a look at this from a pure syntax point first to help get you straightened out on that end.

  1. When you are creating a function the syntax is: def function_name(): You have forgotten the parenthesis.
  2. We are wanting our function to take an argument, therefore we need something similar to def most_classes(busy_teacher):
  3. You are attempting to find the length of strings improperly and while I understand what you are attempting to do, you don't want to be finding the length of strings, but of the length, number, of items in the dictionary. From the Python Docs:

len(s): Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

See if that information can get you started in the right direction. Post back if you are still stuck.

Happy coding,