Little helper for handling entity clusters
Project description
Usage
Eche provides a ClusterHelper
class to conveniently handle entity clusters.
from eche import ClusterHelper
ch = ClusterHelper([{"a1", "b1"}, {"a2", "b2"}])
print(ch.clusters)
{0: {'a1', 'b1'}, 1: {'a2', 'b2'}}
Add an element to a cluster
ch.add_to_cluster(0, "c1")
print(ch.clusters)
{0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}}
Add a new cluster
ch.add({"e2", "f1", "c3"})
print(ch.clusters)
{0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}
Remove an element from a cluster
ch.remove("b1")
print(ch.clusters)
{0: {'a1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}
The __contains__
function is smartly overloaded. You can check if an entity is in the ClusterHelper
:
"a1" in ch
# True
If a cluster is present
{"c1","a1"} in ch
# True
And even if a link exists or not
("f1","e2") in ch
# True
("a1","e2") in ch
# False
To know the cluster id of an entity you can look it up with
print(ch.elements["a1"])
0
To get members of a cluster either use
print(ch.members(0))
{'a1', 'b1', 'c1'}
or simply
print(ch[0])
{'a1', 'b1', 'c1'}
More functions can be found in the Documentation.
Installation
Simply use pip
for installation:
pip install eche
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 Distribution
eche-0.2.1.tar.gz
(11.6 kB
view details)
Built Distribution
eche-0.2.1-py3-none-any.whl
(10.3 kB
view details)
File details
Details for the file eche-0.2.1.tar.gz
.
File metadata
- Download URL: eche-0.2.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27f0d6fc2bfe3f27361bd1205b2b88d92b30acf99032eef00449a8ab0de348b0 |
|
MD5 | 73d407fe1b6a16db9d6d619234a69660 |
|
BLAKE2b-256 | 02f3dacb63e2d2054a22dbd403912eafb8c49f98dabf8be3e3c0b8ca694f5c3c |
File details
Details for the file eche-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: eche-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277c1fe5dbe40ac92d5eca00917bcb278ccb987f7bf044df885da41779330ad7 |
|
MD5 | d21e99c7956c8ec9f08a32086c5c4e7b |
|
BLAKE2b-256 | e4a49f497a6cec96f97e5dffcc0929c9d8dadc50539298f923a2b64dfe5fec2e |