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

I can run this in my computer without problem but why here it is says Didn't get the right output

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(item):

  course = []
  for value in COURSES:
        if not item - COURSES[value]  :
              course += {value}           
  return course

print(covers({"Python"}))

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(item):

      course = []
      for value in COURSES:
            if not item - COURSES[value]  :
                  course += {value}           
      return course


print(covers({"Python"}))
Ismail KOÇ
Ismail KOÇ
1,748 Points

Be careful for spaces (before statement, you can add tab (one tab, two tab, three tab, ...)) and (before write : (do not add space))

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close. The challenge wording can be interpreted more strictly than necessary. The challenge is looking for simple overlap and is not look to see if the supplied set is a proper subset of a courses topics. Using an intersection() or & instead of subtraction will pass Task 1.

Post back if you have more questions. Good luck!!