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 trialthomas2017
1,342 PointsPython Collection Set Math Task 2 of 2
For this exercise I understand the concept but it still doesn't let me pass. Perhaps its the syntax that I messed up on but I just can't figure what it is. Please let me know if someone can catch my mistake. 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(arg):
set1 = []
for course, topics in COURSES.items():
if topics & arg:
set1.append(course)
return set1
def covers_all(special_set):
courses_list = []
for course, topics in COURSES.items():
if(topics & special_set) == special_set:
courses_list.append(course)
return courses_list
4 Answers
Logan R
22,989 PointsMaybe try refreshing your page?
I pasted in your code and it worked for part 1 and for part 2 without any changes lol.
thomas2017
1,342 PointsWell you're much faster than I am :'( I think we can also use >= to see if every element in topics is present in v. I couldn't get it to work though.
*this is from python document set >= other Test whether every element in other is in the set.
thomas2017
1,342 PointsHey thanks Logan, I must have made like 20 changes to get to this answer...
Logan R
22,989 PointsGlad to be of help! I actually just did this challenge myself like 10 minutes ago xD
thomas2017
1,342 PointsI'm curious as to how long it took you to get this problem right?
Logan R
22,989 PointsProbably about 1-2 minutes, top. But my covers_all
method kind of cheats lol.
def covers(topics):
cs = []
for k, v in COURSES.items():
if v.intersection(topics):
cs.append(k)
return cs
def covers_all(topics):
cs = []
for k, v in COURSES.items():
if len(v.intersection(topics)) == len(topics):
cs.append(k)
return cs