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 trialvictor E
19,146 PointsI think my issues is that the argument given is not unpacked, but idk
it is simply adding every item to the list. what am I missing?
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(topics):
lst = []
for key, value in COURSES.items():
if topics & COURSES[key]:
lst.append(key)
return lst
def covers_all(topics):
lst2 = []
for key, value in COURSES.items():
if topics & COURSES[key]
lst2.append(key)
return lst2
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsYour code for covers
and covers_all
is the same. The first successfully checks "where the supplied set and the course's value (also a set) overlap." that is, if any of the topics are also in the course set. The second is supposed to verify that all of the topics are contained with the course topics. In this case, a simple "and" is insufficient.
Looking at the set operations available, which would check if every element in a set is contained in another set?
Post back if you need more help. Good luck!!
victor E
19,146 Pointsvictor E
19,146 Pointswell i tried using what you recommended but i still seem to be getting an error. the fact that I have not been on for a week does not help lol.
[MOD: added ```python formatting -cf]
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsYou are very close. You should be using
COURSES[key]
notCOURSES[value]
. You are checking if thetopics
cover every topic in the course instead of the course covering topic in thetopics
set. Hint: reverse the>=
to<=
Post back if you need more help. Good luck!