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 trialHussein Amr
2,461 Points2nd step of the challenge
stuck
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(argg):
courses_args = []
for name in set(COURSES.keys()):
if len(argg.intersection(COURSES[name])):
courses_args.append(name)
return courses_args
def covers_all(param):
lista = []
for k , v in COURSES.items():
if len(param.issubset(v)):
lista.append(k)
return lista
2 Answers
Steven Parker
231,269 PointsHere's a hint: What if you used a method like you did for the first task, but instead of testing that the intersection was not empty, tested to see if it was the same as the passed-in set?
Hussein Amr
2,461 PointsSteven Parker ahh man its not working :/ look at this way though why is it not working either
def covers_all(param):
lista = []
for name in COURSES:
for item in COURSES[name]:
if param.issupset(item):
lista.append(name)
return lista
Steven Parker
231,269 PointsIt doesn't look like you read my last message where I said, "I was suggesting that you still do the intersection, but instead of taking the length of it, compare it directly to the argument set that was passed in to see if they are the same."
Hussein Amr
2,461 PointsSteven Parker I did read it Steven and I did try it , but I want to learn from my mistake
Steven Parker
231,269 PointsOK, just remember there will always be many ways to write something that won't work. I was just suggesting one approach you could take that would.
Happy coding!
Hussein Amr
2,461 PointsHussein Amr
2,461 PointsSteven Parker didn't work lad :/
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThat's not quite what I was hinting. In your other method, you used the intersection, and took the length of it. I was suggesting that you still do the intersection, but instead of taking the length of it, compare it directly to the argument set that was passed in to see if they are the same.