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) Sets Set Math

Why is it telling me that it can't find covers?

This code works in workspaces but in the challenge its telling me that it can't find the covers function. what am I doing wrong

sets.py
def covers(topic_sets):

    COURSES = {
    "Python Basics": {"Python", "functions", "variables",
                      "booleans", "integers", "floats",
                      "arrays", "strings", "exceptions",
                      "conditions", "input", "loops"},
    "Java Basics": {"Java", "strings", "variables",
                    "input", "exceptions", "integers",
                    "booleans", "loops"},
    "PHP Basics": {"PHP", "variables", "conditions",
                   "integers", "floats", "strings",
                   "booleans", "HTML"},
    "Ruby Basics": {"Ruby", "strings", "floats",
                    "integers", "conditions",
                    "functions", "input"}
    }

    course = []
    for key, val in  COURSES.items():       
        for each in topic_sets:
            if each in val:
                course.append(key)
    return course
Ismail KOÇ
Ismail KOÇ
1,748 Points
        for each in topic_sets:
            if each in val:
                course.append(key)

COURSES must be out of function and function can take single argument (input value), at this (first code in my comment) we have single argument and we do not need for loop, you need to compare value of lists for intersection

for key, val in  COURSES.items():       
        if topic_sets.intersection(COURSES[key]):
            course.append(key)
return course

if you need help for second step, check this link (can you upvote my comment?)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

The given COURSE dictionary should be left outside of the function covers.

:point_right: move the function declaration line below the COURSES dict and it passes Task 1.

Post back if you need more help. Good Luck!!