Initial commit

This commit is contained in:
Michael Reber
2019-11-15 12:59:38 +01:00
parent 40a414d210
commit b880c3ccde
6814 changed files with 379441 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
#A new empty set
color_set = set()
color_set.add("Red")
print(color_set)
#Add multiple items
color_set.update(["Blue", "Green"])
print(color_set)

View File

@@ -0,0 +1,5 @@
setp = set(["Red", "Green"])
setq = setp.copy()
print(setq)
setq.clear()
print(setq)

View File

@@ -0,0 +1,6 @@
#Create a new empty set
x = set()
print(x)
#Create a non empty set
n = set([0, 1, 2, 3, 4])
print(n)

View File

@@ -0,0 +1,5 @@
setp = set(["Red", "Green"])
setq = set(["Green", "Red"])
#A shallow copy
setr = setp.copy()
print(setr)

View File

@@ -0,0 +1,5 @@
setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
#Symmetric difference
setc = setx ^ sety
print(setc)

View File

@@ -0,0 +1,5 @@
#Union
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
seta = setx | sety
print(seta)

View File

@@ -0,0 +1,5 @@
#Intersection
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
setz = setx & sety
print(setz)

View File

@@ -0,0 +1,7 @@
setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
setz = setx & sety
print(setz)
#Set difference
setb = setx - setz
print(setb)

View File

@@ -0,0 +1,6 @@
#Create a set
seta = set([5, 10, 3, 15, 2, 20])
#Find maximum value
print(max(seta))
#Find minimum value
print(min(seta))

View File

@@ -0,0 +1,4 @@
#Create a set
seta = set([5, 10, 3, 15, 2, 20])
#Find the length use len()
print(len(seta))

View File

@@ -0,0 +1,4 @@
#Create a set
num_set = set([0, 1, 2, 3, 4, 5])
for n in num_set:
print(n)

View File

@@ -0,0 +1,5 @@
#Create a new set
num_set = set([0, 1, 2, 3, 4, 5])
#Discard number 4
num_set.discard(4)
print(num_set)

View File

@@ -0,0 +1,5 @@
num_set = set([0, 1, 3, 4, 5])
num_set.pop()
print(num_set)
num_set.pop()
print(num_set)

View File

@@ -0,0 +1,11 @@
setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
setz = set(["mango"])
issubset = setx <= sety
print(issubset)
issuperset = setx >= sety
print(issuperset)
issubset = setz <= sety
print(issubset)
issuperset = sety >= setz
print(issuperset)

View File

@@ -0,0 +1,8 @@
x = frozenset([1, 2, 3, 4, 5])
y = frozenset([3, 4, 5, 6, 7])
#use isdisjoint(). Return True if the set has no elements in common with other.
print(x.isdisjoint(y))
#use difference(). Return a new set with elements in the set that are not in the others.
print(x.difference(y))
#new set with elements from both x and y
print(x | y)