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

scraching my head, can't see where i did wrong(task1)

I checked the logic back and forth and couldn't see any issues, but the code couldn't pass, anyone knows why?

sets.py
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"}
}


def covers(set1):
    course_list = []
    for k,v in COURSES.items():
        if v.intersection(set1):
            course_list.append(k)
    return course_list

1 Answer

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

Hello Peng,

The issue is that the code you have contains a mix of spaces and tabs. So even though a tab looks the same as 4 spaces in the editor, Python thinks they are different. Unfortunately, Python is very sensitive to they way you indent, so this messes up the way the code runs.

In your example specifically, in your cover function, you have tabs in three places:

  1. On the line defining course_list = []
  2. The indenting inside the if statement, i.e., course_list.append
  3. In front of the return statement.

If you take out the tabs and convert them to spaces, the code should work. (Shortcut: copy your code right out of this forum post, since tabs automatically get turned into spaces when code is displayed here.)

In the future, it would be a good idea to set your Workspaces (or any local editor you are using) to use spaces instead of tabs for indenting (see the bottom right corner of the editor window in Workspaces). That way, you should be able to avoid this issue and put your energy into the fun part of coding! :-)

I hope this helps!