Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Sets Set Math

Duyen Huynh Ngoc Phuong
Duyen Huynh Ngoc Phuong
3,494 Points

Can you help me to figure what is wrong with my code. I cannot pass the challenge.

create something a bit more refined. Create a new function named covers_all that takes a single set as an argument. Return the names of all of the courses, in a list, where all of the topics in the supplied set are covered. For example, covers_all({"conditions", "input"}) would return ["Python Basics", "Ruby Basics"]. Java Basics and PHP Basics would be exclude because they don't include both of those topics.

def covers_all(single_set):
    new_list = []
    for key, value in COURSES.items():
        if (single_set & value)==single_set:
             new_list.append(key)
    return new_list
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 B-asics": {"PHP", "variables", "conditions",
                   "integers", "floats", "strings",
                   "booleans", "HTML"},
    "Ruby Basics": {"Ruby", "strings", "floats",
                    "integers", "conditions",
                    "functions", "input"}
}

def covers_all(single_set):
    new_list = []
    for key, value in COURSES.items():
        if (single_set & value)==single_set:
            new_list.append(key)
    return new_list

def covers(arg):
    hold = []
    for key, value in COURSES.items():
        if value & arg:
            hold.append(key)
    return hold

2 Answers

Don Newcomb
Don Newcomb
4,755 Points

I looked at your problem and tried to pass it, but it would not pass do to the "-" you placed here "PHP B-asics": just change that to "PHP Basics": and it should work fine. that was the only thing I found wrong :)

Steven Parker
Steven Parker
221,328 Points

Good catch! :+1: I didn't even think that the provided data might have been changed. I only pasted in the code portion.

Steven Parker
Steven Parker
221,328 Points

You solution looks good. So I pasted it directly into the challenge and it passed. Does it not pass for you?

Duyen Huynh Ngoc Phuong
Duyen Huynh Ngoc Phuong
3,494 Points

Yes, I tried it many times, the first challenge passed, but the second one did not.

Duyen Huynh Ngoc Phuong
Duyen Huynh Ngoc Phuong
3,494 Points

I have tried to log out of my account and logged in again. Luckily the solution is passed this time. Thank you

Steven Parker
Steven Parker
221,328 Points

Don found it .. a stray character somehow got inserted into the supplied data.