KeySet with 4 classes to represent concepts of All, None, Some, and AllExceptSome
Project description
key_set
Python port of KeySet in TypeScript and KeySet in Ruby
KeySet with 4 classes to represent concepts of All, None, Some, and AllExceptSome, the last 2 with a set of keys, and all with intersection, difference, union, inversion, and inclusion calculations.
Limitations
- for now, only KeySet of strings
- no ComposedKeySet yet (see KeySet in TypeScript)
KeySetType
enum
Enum that represents the 4 types of KeySets:
ALL
represents the entirety of possible keys (𝕌
)NONE
represents an empty set (∅
)SOME
represents a concrete set (A ⊂ 𝕌
)ALL_EXCEPT_SOME
represents the complementary of a set, all the elements except the given ones (A' = {x ∈ 𝕌 | x ∉ A}
) _(see Complement in Wikipedia)*
Creation
Build your KeySets using the build functions
from key_set import build_all, build_none, build_some_or_none, build_all_except_some_or_all
build_all() # => returns a new instance of KeySetAll
build_none() # => returns a new instance of KeySetNone
build_some_or_none([]) # returns a new instance of KeySetNone
# returns a new instance of KeySetSome with keys {'a', 'b', 'c'} (in a unique set)
build_some_or_none({'a', 'c', 'b'})
build_some_or_none(['a', 'c', 'b', 'c'])
build_all_except_some_or_all([]) # returns a new instance of KeySetAll
# returns a new instance of KeySetAllExceptSome with keys {'a', 'b', 'c'} (in a unique set)
build_all_except_some_or_all({'a', 'c', 'b'})
build_all_except_some_or_all(['a', 'c', 'b', 'c'])
KeySet
classes
Methods exposed:
key_set_type()
returns the KeySetType
enum
elements()
returns the set with the elements. It will be blank for All
and None
.
represents_xxx()
methods
represents_all
: returns True if the KeySet is ALLrepresents_none
: returns True if the KeySet is NONErepresents_some
: returns True if the KeySet is SOMErepresents_all_except_some
: returns True if the KeySet is ALL_EXCEPT_SOME
invert()
Returns a new KeySet that represents the inverse Set of this one.
ALL
<->NONE
SOME
<->ALL_EXCEPT_SOME
intersect(other)
Returns a new KeySet with the intersection (A ∩ B) of both Sets: a set that contains the elements included in both sets.
union(other)
Returns a new KeySet with the union (A ∩ B) of both Sets: a set that contains the elements in any of the sets.
difference(other)
Returns a new KeySet with the difference (A - B) of the Sets: a set that contains the elements of A that are not in B.
includes(element)
Returns True if the set that this KeySet represents contains the given element.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file key_set-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: key_set-1.1.1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7193d47bd420884b5757a7dfd12ccaa4dd8709b73abd43684824d2dcb4961a |
|
MD5 | f0544a1577bcb9c44554d78f4dda2207 |
|
BLAKE2b-256 | fd131b6f2a55d0f2a8fb84bf6e6669909fd272b8f68b2fad19fe03ce5aeb4f5f |