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 a list of courses from COURSES where the supplied set and the course's value (also a set) overlap.

Not looking for the solution, I just want to know if I understand the question. I have what I think the point of the challenge is, commented out inside the function definition. Am I on the right track?

#these are the instructions
# write a function named covers
# that accepts a single parameter,
# a set of topics
# return a list of courses from COURSES
# where the supplied set
# and the course's value
# (also a set) overlap
# example, covers({"Python"}) 
# would return ["Python Basics"]
# .......................................................

def covers(topics): # topics = type set 
    list_of_courses = [] # the key for topics that overlap
    # compare topics w/ dct value
    # if topics and value overlap
    # append key to list_of_courses

    return list_of_courses


COURSES = { # type = dict 
    # key = type string value = type set
    "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"}
}

set_of_topics = {"boolean", "integers",  "strings"}

# set of topics = type set
covers(set_of_topics)

Thanks Umesh for taking a look.

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Logic looks alright to me :)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I agree. Moving comment to Answer. Marking Best Answer! Thanks Umesh Ravji!