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 trialSerge Kovalenko
9,526 PointsExample works perfectly on my machine but doesn't pass test criteria of the test.
How come this code is not passing treehouse validation tests? What's wrong? Does work very well on my machine.
def covers(*topics): common_topics = [] for course in COURSES: if len(set(topics).intersection(COURSES[course])) > 0: common_topics.append(course)
return common_topics
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"}
}
import json
def covers(*topics):
common_topics = []
for course in COURSES:
if len(set(topics).intersection(COURSES[course])) > 0:
common_topics.append(course)
return json.dumps(common_topics)
2 Answers
Steven Parker
231,236 PointsBe careful about testing a challenge in an external REPL or IDE.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
In this case, the challenge did not ask for anything in JSON format. You won't need that library and you can return your list directly.
Also, the challenge says your function should take the incoming set as a single parameter, you won't need the "splat" operator ("*
").
Serge Kovalenko
9,526 PointsSteven,
thank you. I am indeed misunderstood that function required only single parameter, not a list. That was the root of the problem. Json library used to provide an output in a form required by the challenge - {"aaa","bbb"} rather then {'aaa', 'bbb'}