This commit is contained in:
2024-09-14 12:28:16 +02:00
parent 148cd55409
commit e420899612
5 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#Sets are lists with no duplicate entries. Let's say you want to collect a list of words used in a paragraph:
print(set("my name is Eric and Eric is my name".split()))
# Sets are a powerful tool in Python since they have the ability to calculate differences and intersections between other sets. For example, say you have a list of participants in events A and B:
#To find out which members attended both events, you may use the "intersection" method:
a = set(["Jake", "John", "Eric"])
print(a)
b = set(["John", "Jill"])
print(b)
print(a.intersection(b))
#To find out which members attended only one of the events, use the "symmetric_difference" method:
print(a.symmetric_difference(b))
#To find out which members attended only one event and not the other, use the "difference" method:
print(a.difference(b))
#To receive a list of all participants, use the "union" method:
print(a.union(b))