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 trial

Python

Why isn't this passing? What am I missing?

OK, let's create something a bit more refined. Create a new function named covers_all that takes a single set as an argument. Return the names of all of the courses, in a list, where all of the topics in the supplied set are covered.

For example, covers_all({"conditions", "input"}) would return ["Python Basics", "Ruby Basics"]. Java Basics and PHP Basics would be excluded because they don't include both of those topics

def covers_all(topics):
    result = [] 
    for key, value in COURSES.items():
        if topics & COURSES.keys() == topics:
            result.append(key)
    return result

Hi Peter,

It doesn't make much sense to be checking the keys and not the values in your if check. You are looking to see if the value already exists not the key.

2 Answers

The problem is in the If section.

if topics & COURSES.keys() == topics:

When you input {"conditions", "input"} as a parameter.
type(topics) = 'set' type(COURSES.keys()) = 'dict_keys' in order to get .intersection() to work; both operands must both equal to sets.

What is needed? Access the set of the dictionary (COURSES). and compare it to the similarities of the values and the set of the dictionary(COURSES). {hint: if x[0] = y & x[0]}: you can also use the set() method to convert an iterable. Hope this helps, Carlos A. Marin

Thanks @kylehartigan. I miss read the question. I now updated to just the values and still not passing. Any idea?

def covers_all(topics):
    result = [] 
    for key, value in COURSES.items():
        if topics & COURSES.value():
            result.append(value)
    return result