Set
A collection of unique items, unordered and unindexed.
Create
Create a set
| Action |
Code |
Details |
|
Empty set
|
|
{} defines a dictionary! |
|
Define with values
|
{'apple', 'banana', 'pear'}
|
|
|
From tuple
|
|
|
|
From list
|
|
|
|
From iterable (consumes)
|
|
|
|
Union from a collection of sets
|
|
|
Test
| Action |
Code |
Details |
|
Is set or subclass
|
|
|
|
Is set and not subclass
|
|
|
|
Empty
|
|
|
|
Not empty
|
|
|
|
Contains value v
|
|
|
Contains None
|
|
|
|
Contains all of the given values
|
|
|
|
Contains all of the given values
|
|
|
|
Contains any of the given values
|
not x.isdisjoint([v1, v2])
|
|
|
Contains none of the given values
|
|
|
Compare with another set
| Action |
Code |
Details |
|
Sets share no values
|
|
|
|
Set is a subset of the other: all values of x are in y
|
|
|
|
Set is a superset of the other: all values of y are in x
|
|
|
| Action |
Code |
Details |
|
Number of (unique) values
|
|
|
|
Hash
|
|
|
Update
Grow
| Action |
Code |
Details |
|
Add value if needed
|
|
|
|
Add multiple values if needed
|
x.update(['strawberry', 'kiwi'])
|
|
Shrink
| Action |
Code |
Details |
|
Remove all values (clear)
|
|
|
|
Remove value
|
|
Throws error if value is missing |
|
Remove value if needed
|
|
|
Derive
Combine
Combine with another set
| Action |
Code |
Details |
|
Union with another set
|
|
|
|
Union with another set
|
|
|
|
Intersection with another set: get values which are present in both sets
|
|
|
|
Intersection with another set: get values which are present in both sets
|
|
|
|
Difference to another set: get values which are not present in the other set
|
|
|
|
Difference to another set: get values which are not present in the other set
|
|
|
|
Symmetric difference with another set: get values that are not present in both sets
|
|
|
|
Symmetric difference with another set: get values that are not present in both sets
|
x.symmetric_difference(y)
|
|
Convert
The order of the values in the output should not be relied on
| Action |
Code |
Details |
|
Tuple of values
|
|
|
|
List of values
|
|
|