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 (2016, retired 2019) Dictionaries Teacher Stats

Byron Farrell
Byron Farrell
5,700 Points

Working in work spaces but not in code challenge section

My function most_courses(var) does what is asked for in work spaces but I get an error saying it cant find most_courses

# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
# Each key will be a Teacher and the value will be a list of courses.
# Your code goes below here.

def num_teachers(var):
    return len(var.keys())

def num_courses(var):
    num = 0
    for item in var.values():
        num += len(item)

    return num

def courses(var):
    c = []

    for item in var.values():
    return c

def most_courses(var):
    mx = 0
    ky = "N/a"
    vl = "N/a"

    for item in var:
        v = var[item]
        if ( mx < len(var[item])):
            mx = len(t.values())
            ky = item
            vl = v
    return ky

2 Answers

Louise St. Germain
Louise St. Germain
19,424 Points

I copied your code above directly into the challenge with no changes, and it worked fine! Looks like it might be something with the formatting (tabs or spaces) in the challenge editor. Maybe try just copying the code from your forum post above into the challenge?

This seems to be a common problem with the challenge editor, unfortunately...

Piggybacking on Louise's answer; I've had issues when using tabs in workspaces then copying over to the code challenges (which use spaces by default). The easiest solution for Python is to use 2 spaces in workspaces when you tab.