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 hashes)
Built Distribution
Close
Hashes for propgraph-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef8eb644dd9d90577e9a1b996a6761e16b743e214c3fce9524670b5d4a0a4804 |
|
MD5 | 68085c56926c24fbd971d78c4eb65f5b |
|
BLAKE2b-256 | d8f7a3391c74319130cb9ab31c96975af56b26310f7c7a3c64eeae8139e2b997 |