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

Couldn't find `covers_all`

Can anyone help me understand why it shows this error? There is for sure no typo in the function name...

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_all(single_set):
    single_set = set(single_set)
    all_topics_covered = []
    for x, y in COURSES.items():
        if y & set11 == set11:
            all_topics_covered.append(x)
    return all_topics_covered


def covers(single_set):
    overlap_list = []
    for course in COURSES:
        overlap_set = single_set & COURSES[course]
        if len(overlap_set) > 0:
            overlap_list.append(course)
    return overlap_list    
Yuyang Peng
Yuyang Peng
5,665 Points

hmm I think it may be that you have an undefined variable named set11?

3 Answers

The idea how it works is following:

for x, y in COURSES.items():

This line is unpacking the tuple assigning the key of COURSES dictionary to x and the values (which is a tuple in this exercise) to y and iterates through each tuple created by 'COURSES.items()'.

if y & single_set== single_set:

Then you just check whether the interference of the argument which you read in and the tuple from dictionary is the same as the argument, then it means that whatever you have read in your argument is fully covered in the tuple from COURSES dictonary.

all_topics_covered.append(x)

If the above condition is met this just stored the name of the course (key of the COURSES dictionary) into a list

Hope that helps!

Yuyang Peng
Yuyang Peng
5,665 Points

Yep it totally makes sense, had two days off lol ,I am learning OO now. Thank you Jakub!

Right!! I've been doing it locally on my machine where I had on the beginning the argument called set11.

Thanks Yuyang!

Yuyang Peng
Yuyang Peng
5,665 Points

Great! That's okay Jakub Could you explain the set11 code please ? I also solved this problem just this afternoon, I attached my post down there. Feel free to have a look. But I think your method is better

https://teamtreehouse.com/community/i-tried-my-best-on-setspy-been-struggling-for-an-hour-help

So set11 has to be the argument of a covers_all function, you just need to replace it with 'single_set' or change the name of the argument to set11 :)