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
Adam Harms
9,826 Pointssets.py challenge
Can anyone please explain why my code is not working? It works fine when I use in on my computer but it will not work in the treehouse console.
Directions are, Let's write some functions to explore set math a bit more. We're going to be using this COURSES dict in all of the examples. Don't change it, though! So, first, write a function named covers that accepts a single parameter, a set of topics. Have the function return a list of courses from COURSES where the supplied set and the course's value (also a set) overlap. For example, covers({"Python"}) would return ["Python Basics"].
def covers(topic):
new_list = []
for keys, value in COURSES.items():
if topic in value:
new_list.append(keys)
return new_list
[MOD: fixed formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsYou're on the right track. Your solution checks if a single item topic is contained within the topics of each course in COURSES. However, the challenge is to verify that all of the topics passed to the function as a set are each contained within the topics of a course in COURSES. There may or may not be more than one topic passed into the function. The goal of the challenge is to use set comparisons to see if all of the passed in topics are in each course.
Various ways to compare sets can be found in the docs. Good luck!!!