A graph structure that can take arbitrary properties.
Project description
prop-graph
A graph structure that can take arbitrary properties.
Usage
In the examples that follow, I'll be working with a graph that looks as follows:
a g
/ \ / \
b c h i
/ \ / \ /
d e f
Build graph
graph = Graph([
("a", "b"),
("a", "c"),
("b", "d"),
("b", "e"),
("c", "e"),
("c", "f"),
("g", "h"),
("g", "i"),
("h", "f"),
])
graph.print()
# a
# b
# d
# e
# c
# e
# f
# g
# h
# f
# i
Add properties
props = {
"c": "interesting",
"g": "interesting",
}
graph.add_property("type", props)
Finding nodes
parent_ids = graph.find_by(lambda n: len(n.children) > 0)
print(parent_ids)
# ['a', 'b', 'c', 'g', 'h']
root_ids = graph.find_by(lambda n: len(n.parents) == 0)
print(root_ids)
# ['a', 'g']
interesting_ids = graph.find_by(lambda n: n["type"] == "interesting")
print(interesting_ids)
# ['c', 'g']
Deleting nodes
graph.delete_by(lambda n: n["type"] == "interesting")
graph.print()
# a
# b
# d
# e
# e
# f
# h
# f
# i
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
propgraph-0.1.1.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file propgraph-0.1.1.tar.gz.
File metadata
- Download URL: propgraph-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3d962890ddfe73bcaf8bab4ff4bf9609192a7178d10c4d0eaffe9580300487f
|
|
| MD5 |
12f5af091946bfbd468dd39458c9498f
|
|
| BLAKE2b-256 |
e231c5de8f9c155975c70cc1593690a4e87d24afeb1c824d04e7c51eb9f4b7cd
|
File details
Details for the file propgraph-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: propgraph-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8eb644dd9d90577e9a1b996a6761e16b743e214c3fce9524670b5d4a0a4804
|
|
| MD5 |
68085c56926c24fbd971d78c4eb65f5b
|
|
| BLAKE2b-256 |
d8f7a3391c74319130cb9ab31c96975af56b26310f7c7a3c64eeae8139e2b997
|