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

Vuk Spasojevic
Vuk Spasojevic
9,491 Points

Task 2 of sets.py returns Bummer although it returns good list as a result. Can you help me what I am doing wrong.

Set topics will always be equal size set or subset of COURSES set. So in any case, for requested condition topics must be entirely included within COURSES set. Finally, topics.intersection(COURSES[key]) must give set topics as a result.

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(topics):
    covers_list = []
    for key in COURSES:
        if COURSES[key].intersection(topics) != set()
            covers_list.append(key)
        else:
            continue
    return covers_list

def covers_all(topics):
    covers_list_all = []
    for key in COURSES:
        if COURSES[key].intersection(topics) == topics:
            covers_list_all.append(key)
        else:
            continue
    return covers_list_all

Hi Vuk, you can try just changing a line of code:

if COURSES[key].intersection(topics) != set()

to this:

if COURSES[key].intersection(topics):

1 Answer

Vuk Spasojevic
Vuk Spasojevic
9,491 Points

Thanks eg3 for the help. Just found the mistake in cover functions, on if statement- typo mistake, I did not put " : ". Thank again.