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

Missing something about how sets work: print(fib.issubset(prime))

fib = {1,2,3,5,8,13,21,34,55,89,174}
prime = {1,2,3,5,7,9,13,17,19,22,29}

# from the python documentation
# ................................................................
#issubset(other)
#set <= other
#Test whether every element in the set is in other.

print(fib.issubset(prime))

#8 in fib, not in prime
#21 in fib, not in prime
#34, 55, 89, 174 in fib, not in prime

# yet, when I run it, returns True

The documentation seems straightforward, but clearly I am missing something.

2 Answers

Steven Parker
Steven Parker
231,236 Points

When I run it, I get False.

I tried it in the Treehouse workspace REPL, and also in my locally-installed Python (version 3.2.5).

Where are you trying it?

Hi Steve, I ran it local, copy and pasted, I'll look at it again. I know it should return false like you got... That time I got False. I swear I ran it 3 or 4 times looking at it each time, cause I was going to use it in some code, and it wasn't doing what I expected. Well thanks for looking.

Chris Komaroff
PLUS
Chris Komaroff
Courses Plus Student 14,198 Points

Thanks for heads up on .issubset(). Maybe a simpler example:

>>> a_set = {1,2,3,4,5}
>>> b_set = {3,4}
>>> a_set.issubset(b_set)
False
>>> b_set.issubset(a_set)
True
>>>