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

Return the names of all of the courses, in a list by using set() function.

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(course): list_of_courses = [] for subject in COURSES.keys(): if course.intersection(COURSES[subject]): list_of_courses.append(subject) return list_of_courses print(covers({"conditions", "input"}))

def covers_all(topic): all_courses = [] for courses in covers(topic): if COURSES[courses].issuperset(topic): all_courses.append(courses) return all_courses print(covers_all({"condition", "input"}))

Hi all! :) I am trying to return the names of all the courses, in a list if every element of the parameter exists in the values of the object COURSES.

In the second function, I am iterating over the 1st function which returns a list of all the classes. But, the overall result is an empty list :(

Can anyone explains why it keeps executing an empty 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 Basics": {"PHP", "variables", "conditions",
                   "integers", "floats", "strings",
                   "booleans", "HTML"},
    "Ruby Basics": {"Ruby", "strings", "floats",
                    "integers", "conditions",
                    "functions", "input"}
}

def covers(course):
    list_of_courses = []
    for subject in COURSES.keys():
        if course.intersection(COURSES[subject]):
            list_of_courses.append(subject)
    return list_of_courses


def covers_all(topic):
    all_courses = []
    for courses in covers(topic):
    if COURSES[courses].issuperset(topic):
        all_courses.append(courses)
    return all_courses

1 Answer

Anthony Crespo
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Crespo
Python Web Development Techdegree Student 12,973 Points

You forgot to Indent the block after your for loop in your covers_all function

def covers_all(topic):
    all_courses = []
    for courses in covers(topic):
        if COURSES[courses].issuperset(topic):
            all_courses.append(courses)
    return all_courses