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 trialPrisca Egbua
1,167 PointsI'm trying to return a list of courses whose course topics intersect with a given set of topics.
My code looks right but it's not correct, Please can someone explain what am doing wrong and what I need to correct. Thank you
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(set1):
for course,sets in COURSES.items():
course_list = []
if set1.intersection(sets):
return course_list.append(course)
1 Answer
Steven Parker
231,269 PointsYou're close, but you have a few issues:
- "course_list" should be initialized only once, before the loop
- there should not be a "return" inside the loop
- the new list should be returned after the loop
I'll bet you can get it now.
Prisca Egbua
1,167 PointsPrisca Egbua
1,167 Pointsit did help, thanks