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 trialAbdulkadir Kollere
1,723 PointsSets issues
The code below gives me the desired result in workspaces as usual but does not allow me to pass the challenge. Kindly assist
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(elem):
keys = COURSES.keys()
for item in elem:
for key in keys:
values = COURSES[key]
if item in values:
print (key)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou have the correct idea. The function needs to return
a list
of the results. One way is to initialize an empty list
at the top of the function, then append()
each found course name instead of printing the matches. Finally, return
the result.
Post back if you need more help. Good luck!!
Abdulkadir Kollere
1,723 PointsAbdulkadir Kollere
1,723 PointsI did the changes as suggested, but it still says did not get the right output from 'covers'. See the code below:
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsSo close! The
return
statement is indented too far. In this position, the function will return after the first match. To fix it, the return should align with thefor
statement.Abdulkadir Kollere
1,723 PointsAbdulkadir Kollere
1,723 PointsThat worked. I often get in trouble with the indentations. Thanks alot!!