Set
Bases: PyoSet[T], ArgsWrapper[T]
flowchart TD
pyochain.core._set.Set[Set]
pyochain.abc._set.PyoSet[PyoSet]
pyochain.abc._collection.PyoCollection[PyoCollection]
pyochain.abc._iterable.PyoIterable[PyoIterable]
pyochain.abc._collection.PyoContainer[PyoContainer]
pyochain.abc._collection.PyoSized[PyoSized]
pyochain.abc._mixins.Checkable[Checkable]
pyochain.abc._mixins.Fluent[Fluent]
pyochain.abc._mixins.Pipe[Pipe]
pyochain.abc._mixins.Tap[Tap]
pyochain.abc.constructors.ArgsWrapper[ArgsWrapper]
pyochain.abc.constructors.FromArgs[FromArgs]
pyochain.abc.constructors.FromIter[FromIter]
pyochain.abc.constructors.Wrapper[Wrapper]
pyochain.abc._set.PyoSet --> pyochain.core._set.Set
pyochain.abc._collection.PyoCollection --> pyochain.abc._set.PyoSet
pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
pyochain.abc.constructors.ArgsWrapper --> pyochain.core._set.Set
pyochain.abc.constructors.FromArgs --> pyochain.abc.constructors.ArgsWrapper
pyochain.abc.constructors.FromIter --> pyochain.abc.constructors.FromArgs
pyochain.abc.constructors.Wrapper --> pyochain.abc.constructors.ArgsWrapper
click pyochain.core._set.Set href "" "pyochain.core._set.Set"
click pyochain.abc._set.PyoSet href "" "pyochain.abc._set.PyoSet"
click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
click pyochain.abc.constructors.ArgsWrapper href "" "pyochain.abc.constructors.ArgsWrapper"
click pyochain.abc.constructors.FromArgs href "" "pyochain.abc.constructors.FromArgs"
click pyochain.abc.constructors.FromIter href "" "pyochain.abc.constructors.FromIter"
click pyochain.abc.constructors.Wrapper href "" "pyochain.abc.constructors.Wrapper"
Set represent an in- memory unordered collection of unique elements.
Implements the collections::abc::Collection Protocol, so it can be used as a standard immutable collection.
The underlying data structure is a frozenset.
Tip
Set(frozenset) is a no-copy operation since Python optimizes this under the hood.
Source code in pyochain/core/_set.pyi
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
__new__(data=(), /, *more)
__new__(data: Iterable[T]) -> Self
__new__(data: T, /, *more: T) -> Self
__new__() -> Self
Create a new Set instance.
If not arguments are provided, an empty Set is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T] | T
|
Initial elements to populate the set with. Defaults to |
()
|
*more
|
T
|
Additional elements to add to the set. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A new |
Example
from pyochain import Set, Iter, Range
data = (0, 1, 2, 3)
# Create a `Set` from an iterable
assert Set(data) == Set(Range(0, 4)) == frozenset(data)
# Create a `Set` from a single, non-iterable element
assert Set(1) == Set((1,)) == Set([1]) == frozenset([1])
# Create a `Set` from multiple elements
assert Set(0, 1, 2, 3) == Set(data)
# Create an empty `Set`
assert Set() == Set([]) == Set(()) == frozenset()
assert repr(Set()) == "Set()"
# If you already have a `frozenset`, you can use it directly without copying:
fs = frozenset(data)
s2 = Set(fs)
assert s2 == Set(data)
find_one: Callable[[object], bool] = lambda x: x == 0
a = s2.iter().find(find_one).unwrap()
b = Iter(fs).find(find_one).unwrap()
assert a is b
Source code in pyochain/core/_set.pyi
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__and__(value)
Return self&value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to perform the intersection with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A new instance of the same class containing the intersection of the two sets. |
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(2, 3, 4)
s3 = s1 & s2
assert s3 == Set(2, 3)
Source code in pyochain/core/_set.pyi
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
__or__(value)
Return self|value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[S]
|
The set to perform the union with. |
required |
Returns:
| Type | Description |
|---|---|
Set[T | S]
|
Set[T | S]: A new |
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(3, 4, 5)
s3 = s1 | s2
assert s3 == Set(1, 2, 3, 4, 5)
Source code in pyochain/core/_set.pyi
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
__sub__(value)
Return self-value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to perform the difference with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A new instance of the same class containing the difference of the two sets. |
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(2, 3, 4)
s3 = s1 - s2
assert s3 == Set(1)
Source code in pyochain/core/_set.pyi
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__xor__(value)
Return self^value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[S]
|
The set to perform the symmetric difference with. |
required |
Returns:
| Type | Description |
|---|---|
Set[T | S]
|
Set[T | S]: A new |
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(2, 3, 4)
s3 = s1 ^ s2
assert s3 == Set(1, 4)
Source code in pyochain/core/_set.pyi
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
__le__(value)
Return self<=value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Example
from pyochain import Set
s1 = Set(1, 2)
s2 = Set(1, 2, 3)
assert s1 <= s2
assert not s2 <= s1
Source code in pyochain/core/_set.pyi
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__lt__(value)
Return self<value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Example
from pyochain import Set
s1 = Set(1, 2)
s2 = Set(1, 2, 3)
assert s1 < s2
assert not s2 < s1
Source code in pyochain/core/_set.pyi
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
__ge__(value)
Return self>=value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(1, 2)
assert s1 >= s2
assert not s2 >= s1
Source code in pyochain/core/_set.pyi
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
__gt__(value)
Return self>value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Set[object]
|
The set to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Example
from pyochain import Set
s1 = Set(1, 2, 3)
s2 = Set(1, 2)
assert s1 > s2
assert not s2 > s1
Source code in pyochain/core/_set.pyi
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
isdisjoint(s)
Return True if two sets have a null intersection.
Source code in pyochain/core/_set.pyi
262 263 264 | |