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

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Set not callable

Ok. This challenge is much tougher than the things demonstrated by Love in the video. I am reading this as meaning that the parameter for the function is a set.
The error message I get says "TypeError: 'set' object is not callable"

So if I can't call a set as an argument for a function how can I use it here?

I am also reading the challenge as stating that each key/value pair in the Dict is a set. But I am not sure how to refer to them in order to use them in the function. Since I can't change the dictionary (see instructions) I don't know how to refer to them in the function as separate sets.

Thanks.

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(myset):
Umesh Ravji
Umesh Ravji
42,386 Points

You are reading it correctly, the function takes only one parameter and that is the set of topics. Do you have any more code from your function?

myset = set()
myset()

That would give you the error message you saw above, trying to call a set like a method.

Nancy Melucci
Nancy Melucci
Courses Plus Student 36,143 Points

I hadn't gotten farther than what I printed because I was stumped. I've managed now to make a set of the Course titles and a list containing the values from COURSES.

I think that I need to make a set out of those values. I am stuck there now. The for-loop that works for making the set of courses doesn't work for the topics. I get this error:

Traceback (most recent call last): File "C:/Users/Nancy/PycharmProjects/treehouse/settheory.py", line 34, in <module> set_topics.add(item) TypeError: unhashable type: 'set'

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"}
}

courses = list(COURSES.keys())
topics = list(COURSES.values())
print(topics)

set_courses = set()
set_topics = set()


for item in courses:
    set_courses.add(item)


print(set_courses)

for item in topics:
    set_topics.add(item)


print(set_topics)

5 Answers

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hi Nancy Melucci

So yes, Kenneth definitely doesn't make his challenges too easy. He wants you to really grasp the concepts of how to work with the data type and using the docs.

I noticed you wrote the covers function but didn't write any logic inside it? Basically you can call the parameter for covers whatever you want (try not to use Python's reserved keywords). So id call it something that it would be holding in our case maybe like topics since we will be getting a set of topics.

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(topics):
    # For the logic you will want to use one of the things
    # Kenneth talked about in his video for comparing two sets
    # Options were: union, intersection, symmetric_difference, difference

Now COURSES is a Dictionary (key/value) pair where the Value is also a Set. Kenneth stated in Task 1 of 2 of this challenge that covers for example could receive something like {"Python"} for a parameter. Which is a set. So our parameter topics is a set and each VALUE of our COURSES dictionary is set. So we can use the methods he taught us to compare them.

Hopefully that helps? I'm trying not to just give you the answer, but guide you to it.

If you write some logic in covers I can get a better idea of where you are getting lost at.

Tommy Seabolt
Tommy Seabolt
22,788 Points
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(param1):
    r_list = []
    for k,v in COURSES.items():
        if param1.issubset(v):
            r_list.append(k)
    return r_list

I'm having the same issues with this challenge but when I run my code in workspaces it gives me the correct answer but fails in the Code Challenge.

The only error I get in the code challenge is "Bummer, try again"

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Are you sure the method .issubset(v) is the one you want for Task 1 of 2?

issubset is returning a list where EVERY item is in the other list.

You may want to look at what each method is doing and what the desired result is. Maybe one where they share some of the same items but not explicitly EVERY item just common items.

Nancy Melucci
Nancy Melucci
Courses Plus Student 36,143 Points

Yes. As I've mentioned in my whiny little way in other places here, I really wish that message was more informative. It's a disincentive to persist. I enjoy Python, although I don't think it's as easy as it's fans proclaim it to be. I really wanted to finish this course.

I hope we can both get there.

NJM

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Nancy Melucci

It is okay to be confused about something, asking questions isn't whining.

I agree the error messages in the challenges aren't exactly the best, I tend to have to have a Workspace going or copy/paste my code over and tinker with it locally on my own machine to try and see the actual Stack Trace error Python gives. I do that anytime a challenge just wont pass.

Tommy Seabolt
Tommy Seabolt
22,788 Points

Chris Howell

OoooooooOOoooOOohhhhhhh......that's silly. But I passed it now. I needed union in place of issubset . Thanks for the help!

bowei zhou
bowei zhou
1,762 Points

def covers_all(a): b = [] for k,v in COURSES.items(): c = v.intersection(a) if c == a: b.append(k) return b

covers_all({"conditions", "input"})

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

(Chris) I did not recognize the dictionary values as sets. I am taking a break now (actually working on one of Guil's courses) and will come back to this over the weekend. Python isn't my strongest language (and I am not particularly strong at any of them, I do love to learn programming tho). I am taking a 16-week junior college class in it starting in 3 weeks...I've studied Python on and off for close to 3 years, trying to get ready for that. I really would like to finish this course.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Nancy Melucci

Well I always tell people I didn't like Python the first time I used it. I had a background in some other languages before it, but now I really love it. The more you learn about it the more you love about it.

Take breaks as needed and come back and tinker with it more. Once you grasp the concepts, data types, and how to work with them. You'll excel up to another point where you get stuck for a bit until you grasp that next concept, the cycle repeats. I've been working with Python for awhile now, I still get stuck on things and have to take breaks and come back with a fresh mind. There is so much to explore in this language. :)