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 trialArihant Tripathy
8,764 PointsI can't understand how to solve this challenge.
I get this error in the REPL - TypeError: unhashable type: 'set'
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):
if topics in COURSES:
return list(topics)
1 Answer
Steven Parker
231,275 PointsYou won't need to convert anything into a list, and as Kirsten points out both your argument and the dictionary values are sets, so you can compare sets using "set math". Any non-empty intersection would be considered an "overlap". When you get to task 2, you might use a subset instead.
Arihant Tripathy
8,764 PointsCOURSES = {
"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):
if COURSES.intersection(topics) == True:
return topics
Now what's wrong?
Steven Parker
231,275 PointsHere's a few additional hints:
- this code returns the original argument unchanged
- if the condition does not pass, nothing at all is returned
- you'll need a loop to check the different sets in each dictionary entry (instead of the whole thing)
- you'll need to construct a list of keys to return after the loop finishes
- while not an error, you don't ever need to compare anything to "True" (just name it)
Kirsten Smith
3,484 PointsKirsten Smith
3,484 PointsSo topics is coming in as a set. Courses is also a set so you can use the set math learned to find the intersection of those.