Set
Class Set
Polymorphic sets
Example: A = Set([1,2,3])
The class Set allows the following operations:
in
)len
)Base Class: list
Overview:
Set (el)
Operator | Meaning |
x + y | a + b à __add__ (a, b), if a is of type Set __radd__(b, a), otherwise |
Elements, wihch are sets themself come first and are sorted by length (cardinality) simultaneous overloading of < <=, >, >=, == and != If A is a Set and b not, A.__cmp__(b) is called for comparing A with b (or vice versa)! | |
x == y | |
x * y | |
x != y | |
str(x) | |
x - y | |
x ^ y |
Method | Meaning |
card () | Cardinality |
difference (B) | Set difference |
insert (e) | Inserts an additional element ti the set |
intersection (B) | Intersection |
issubset (B) | Is A subset of (oder equal to) B? |
issuperset (B) | Is A superset of (oder equal to) B? |
operators () | For documentation only |
powerset () | Powerset (set of alle subsets) |
product (B) | Cartesian product |
symmDiff (B) | Symmetric difference |
union (B) | Union set |
Constructor
Usage: Set(el)
Union (operators + and +=):
Usage: x + y
Description:
a + b à __add__ (a, b), if a is of type Set
__radd__(b, a), otherwise
For ordering sets
Usage:
Description:
Elements, wihch are sets themself come first and are sorted by length (cardinality)
simultaneous overloading of < <=, >, >=, == and !=
If A is a Set and b not, A.__cmp__(b) is called for comparing A with b (or vice versa)!
Usage: x == y
Cartesian product (operator *)
Usage: x * y
Description:
Usage: x != y
Object representation as string (in curly braces)
Usage: str(x)
Description:
Set difference (operators - and -=)
Usage: x - y
Description:
Symmetric difference (operators ^ and ^=)
Usage: x ^ y
Description:
A.card()
Usage: self.card()
Description:
Cardinality
Same as len(A)
A.difference(B)
Usage: .difference(B)
Description:
Set difference
Also operator notation: A - B
Instead of A = A - B
you can write A -= B
.
A.insert(e)
Usage: self.insert(e)
Description:
Inserts an additional element ti the set
A.insert(e) is equivalent to A += Set(e)
A.intersection(B)
Usage: .intersection(B)
Description:
Intersection
Also operator notation: A - B
Instead of A = A & B
you can write A &= B
.
A.issubset(B)
Usage: A.issubset(B)
Description:
Is A subset of (oder equal to) B?
Return value: bool
A.issuperset(B)
Usage: A.issuperset(B)
Description:
Is A superset of (oder equal to) B?
Return value: bool
Set.operators()
Usage: self.operators()
Description:
For documentation only
The following operators are defined in the class Set:
Op. | Function | Examples |
---|---|---|
& | Intersection | A & B; A &= B |
+ | Union | A + B; A += B |
- | Set difference | A - B; A -= B |
^ | Symmetric difference | A ^ B; A ^= B |
* | Cartesian product | A * B; A *= B |
in | is element of | x in A |
A.powerset()
Usage: self.powerset()
Description:
Powerset (set of alle subsets)
A.product(B)
Usage: .product(B)
Description:
Cartesian product
Also operator notation: A * B
Instead of A = A * B
you can write A *= B
.
A.symmDiff(B)
Usage: .symmDiff(B)
Description:
Symmetric difference
Also operator notation: A ^ B
Instead of A = A ^ B
you can write A ^= B
.
A.union(B)
Usage: .union(B)
Description:
Union set
Also operator notation: A + B
Instead of A = A + B
you can write A += B
.