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 Python Collections (2016, retired 2019) Sets Set Math

Hussein Amr
Hussein Amr
2,461 Points

2nd step of the challenge

stuck

sets.py
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
Steven Parker
231,236 Points

Here'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? :wink:

Hussein Amr
Hussein Amr
2,461 Points

Steven Parker didn't work lad :/

def covers_all(param):
    lista = []
    for name in set(COURSES.keys()):
        if len(param) == len(COURSES[name]):
            lista.append(name)
    return lista
Steven Parker
Steven Parker
231,236 Points

That'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.

Hussein Amr
Hussein Amr
2,461 Points

Steven 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
Steven Parker
231,236 Points

It 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
Hussein Amr
2,461 Points

Steven Parker I did read it Steven and I did try it , but I want to learn from my mistake

Steven Parker
Steven Parker
231,236 Points

OK, 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!