0% found this document useful (0 votes)
9 views

Sets

Uploaded by

prachik.aids21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Sets

Uploaded by

prachik.aids21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

------------------------------------------------------------------------

thisset = {"apple", "banana", "cherry", "apple"}


#t1=(2,3,4)
print(thisset)
for x in thisset:
print(x)

thisset={"apple", "banana", "cherry"}


print("banana" in thisset)

----------------------------------------------------------------------

#Once a set is created,

#you cannot change its items, but you can add new items.

thisset = {"apple", "banana", "cherry"}


print(thisset)
print("type of set is", type(thisset))
thisset.add("orange")
print("After adding orange",thisset)

thisset = {"apple", "banana", "cherry"}


print("Original thisset is", thisset)
tropical = {"pineapple", "mango", "papaya"}
thisset.update(tropical)
print("After Updation 1", thisset)

thisset = {"apple", "banana", "cherry"}


mylist = ["kiwi", "orange"]
mytuple =("carrot","onion")
thisset.update(mytuple) #can update list and tuple in sets
thisset.update(mylist)
print("After Updation 2", thisset)

----------------------------------------------------------------------
#thisset = {"apple", "banana", "cherry", "apple", True,1,2}
#print(thisset)
#one will not print here bc it consider True as 1

thisset = {"apple", "banana", "cherry"}


#thisset.clear()
print("this set",thisset)
s1={"orange","lemon","cherry"}
s3=thisset.isdisjoint(s1)#if the value is common and there in the set then the
dissjoin is false otherwise true
print("the value",s3)

---------------------------------------------------------------------

set1={"a","b","c",3}
set2={1,2,3}

set3= set1.union(set2)
#set4=set1.union(set2)
print(set3)
set1={"a","b","c"}
set2={1,2,3}
set1.update(set2)
print(set1)

---------------------------------------------------------------------

#keep only the duplicates

x={"apple", "banana", "cherry"}


y = {"google", "microsoft", "apple"}
x.update(y)
print("Normal Update X",x)

x.intersection_update(y)

print("Intersection Update",x)
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)

You might also like