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 trialLukas Straumann
Python Web Development Techdegree Student 9,588 PointsI don't understand why my code doesn't not answer the code challenges' question. I guess I need help here.
I don't understand why my code doesn't not answer the code challenges' question. I guess I need help here.
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(para):
coursesList = []
for course in COURSES:
if para.issubset(COURSES[course]):# x.issubset(y) returns True, if x is a subset of y.
coursesList.append(course)
return coursesList
2 Answers
Wade Williams
24,476 PointsYou're pretty close, but you need to loop through COURSES for each topic. Your code works if "para" only has 1 item in it, but fails if it has more than 1 item in it.
Here's my code
def covers(topics):
results = []
for topic in topics:
for course in COURSES:
if topic in COURSES[course]:
results.append(course)
return results
Lukas Straumann
Python Web Development Techdegree Student 9,588 PointsThanks a lot Wade Williams. That helped greatly. Merry Christmas soon..