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 trialEthan Gundry
1,162 PointsIntersection returning blank set
I can't seem to figure this one out - I've tried doing something like this:
def covers(topics): new_set = {} for item in COURSES: new_item = topics.intersection(item) new_set.update(new_item) return(new_set)
But it just returns an empty set.
Additionally, I tried doing this:
def covers(topics): item = topics.intersection(topics, COURSES) return item
And I just get back set(). I'm really unsure how to go about it; iterating didn't seem to help at all and I've been at a loss as to what to do, even when looking at similar problems on the web. Any help would be appreciated.
1 Answer
Kirsten Smith
3,484 PointsFirst off, the challenge asks for you to return a LIST, so instead of new_set = {}, you can substitute new_list = []. Secondly, you need to access the list associated with each course, or item based on your setup, not just the item itself. COURSES is a dictionary, item in your code is the key so how would you access the set associated with each key inside your for loop? EX: COURSES["Python Basics"] would give you the set associated with that course.