Set Examples Flashcards
thisset = {“apple”, “banana”, “cherry”}
thisset.add(“orange”)
print(thisset)
{‘banana’, ‘apple’, ‘cherry’, ‘orange’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
z = x.difference(y)
print(z)
{‘cherry’, ‘banana’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
x.difference_update(y)
print(x)
{‘cherry’, ‘banana’}
thisset = {“apple”, “banana”, “cherry”}
thisset.discard(“banana”)
print(thisset)
{‘cherry’, ‘apple’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)
{‘apple’}
x = {"a", "b", "c"} y = {"c", "d", "e"} z = {"f", "g", "c"}
result = x.intersection(y, z)
print(result)
{‘c’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
x.intersection_update(y)
print(x)
{‘apple’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "facebook"}
z = x.isdisjoint(y)
print(z)
True
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
z = x.isdisjoint(y)
print(z)
False
x = {"a", "b", "c"} y = {"f", "e", "d", "c", "b"}
z = x.issubset(y)
print(z)
False
x = {"f", "e", "d", "c", "b", "a"} y = {"a", "b", "c"}
z = x.issuperset(y)
print(z)
True
fruits = {“apple”, “banana”, “cherry”}
fruits.pop()
print(fruits)
{‘banana’, ‘cherry’}
fruits = {“apple”, “banana”, “cherry”}
fruits.remove(“banana”)
print(fruits)
{‘apple’, ‘cherry’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
z = x.symmetric_difference(y)
print(z)
{‘google’, ‘microsoft’, ‘banana’, ‘cherry’}
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"}
x.symmetric_difference_update(y)
print(x)
{‘google’, ‘microsoft’, ‘banana’, ‘cherry’}