Main Overview

Class Set

Class Set
Polymorphic sets
Example: A = Set([1,2,3])
The class Set allows the following operations:

Base Class: list

Overview:

Constructor

Set (el)

Operators

OperatorMeaning
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

Object Methods

MethodMeaning
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

Set

Constructor

Usage: Set(el)


Operators

x + y

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)!


x == y

Usage: x == y


x * y

Cartesian product (operator *)

Usage: x * y

Description:


x != y

Usage: x != y


str(x)

Object representation as string (in curly braces)

Usage: str(x)

Description:


x - y

Set difference (operators - and -=)

Usage: x - y

Description:


x ^ y

Symmetric difference (operators ^ and ^=)

Usage: x ^ y

Description:


Object Methods

card

A.card()

Usage: self.card()

Description:
Cardinality
Same as len(A)


difference

A.difference(B)

Usage: .difference(B)

Description:
Set difference
Also operator notation: A - B
Instead of A = A - B you can write A -= B.


insert

A.insert(e)

Usage: self.insert(e)

Description:
Inserts an additional element ti the set
A.insert(e) is equivalent to A += Set(e)


intersection

A.intersection(B)

Usage: .intersection(B)

Description:
Intersection
Also operator notation: A - B
Instead of A = A & B you can write A &= B.


issubset

A.issubset(B)

Usage: A.issubset(B)

Description:
Is A subset of (oder equal to) B?
Return value: bool


issuperset

A.issuperset(B)

Usage: A.issuperset(B)

Description:
Is A superset of (oder equal to) B?
Return value: bool


operators

Set.operators()

Usage: self.operators()

Description:
For documentation only
The following operators are defined in the class Set:

Op.FunctionExamples
&IntersectionA & B; A &= B
+UnionA + B; A += B
-Set differenceA - B; A -= B
^Symmetric differenceA ^ B; A ^= B
*Cartesian productA * B; A *= B
inis element ofx in A
This method is for documentation only. It has no effect.


powerset

A.powerset()

Usage: self.powerset()

Description:
Powerset (set of alle subsets)


product

A.product(B)

Usage: .product(B)

Description:
Cartesian product
Also operator notation: A * B
Instead of A = A * B you can write A *= B.


symmDiff

A.symmDiff(B)

Usage: .symmDiff(B)

Description:
Symmetric difference
Also operator notation: A ^ B
Instead of A = A ^ B you can write A ^= B.


union

A.union(B)

Usage: .union(B)

Description:
Union set
Also operator notation: A + B
Instead of A = A + B you can write A += B.