57. Sets Flashcards
what is a set
unordered collections of objects
what does a set do
does not print two of the same value when written is my_set =[1,2,3,4,5}
print(my_set)
printsonly 1,2,3,4,5
how will put a list into a set to remove duplicates?
print(set( my_list) )
how do you check something in a set like
my_set ={1,2,3,4,5,5}
what does len do in this case>
do
print(1 in my_set)
prints true
will put lenghth, but in a way that not include dupl.
.difference do when you have two sets?
- so, you write
print(first set.differnce9second set))
what does .discard() do to a set
takes away the # in the ()
what does .difference_update () do
tells you the differene+ the update update it
.intersection()
prints what both together have in common
.iddisjoint()
-nothing in common
.union
unites sets and takes away duplicates when you have two sets
as print(my_set | your_set)
.issubset
what does (my_set.issubset(your_set ))
inside of the circle of the other, because the other one is smaller, and in it
example
set = 2,3
2set = 2345
not accurate, but the idea is there