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

angel moreta
angel moreta
2,912 Points

What I'm doing wrong here ?

I run the code on my terminal and i get the right answer which is ["python basic","java basics","php basics","ruby basics"] then i copy/paste my code to the challenge environment and i get a bummer. Why???

this challenge is super confusing. I dont quite understand what they want me to do.

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(set_of_topics):
    list_of_courses=[]
    for key,value in COURSES.items():#key a str, value a set
        if value & set_of_topics[key]:
            list_of_courses.append(key)
    return list_of_courses

1 Answer

Mckenzie Hessel
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mckenzie Hessel
Full Stack JavaScript Techdegree Graduate 20,437 Points

["python basic","java basics","php basics","ruby basics"] is not necessarily the correct answer. Notice that in the example they enter covers({"Python"}) and the code only returns one course, ["Python Basics"].

They only want your code to return the courses that contain whatever set of topics the computer enters. So if the computer testing your code enters covers({"Ruby"}) then ["Ruby Basics"] should be returned. If the computer enters covers({"input"}) then ["Python Basics", "Java Basics", "Ruby Basics"] should appear, because "input" is contained in those three courses. If covers({"strings"}) is input, then your answer (["python basic","java basics","php basics","ruby basics"]) would be correct because the topic "strings" appears in all four courses