Python Generate the data tree recursively
Project description
Tree Builder
Input
lst = [
{"id": 1, "pid": 0, "name": "Tree - 1"},
{"id": 2, "pid": 1, "name": "Tree - 1 - 1"},
{"id": 3, "pid": 1, "name": "Tree - 1 - 2"},
{"id": 4, "pid": 2, "name": "Tree - 1 - 1- 1"},
{"id": 5, "pid": 0, "name": "Tree - 2"}
]
Usage
pip install data2tree -i https://pypi.org/simple/
from TreeBuilder.builder import BuildTree
tree = BuildTree(record_key="id", parent_record_key="pid").build_tree(lst)
print(tree)
Notes
Parameter | Type | required | Description |
---|---|---|---|
record_key | String | True | record id |
parent_record_key | String | True | parent_record id |
Output
[
{
"id": 1,
"pid": 0,
"name": "Tree - 1",
"child": [
{
"id": 2,
"pid": 1,
"name": "Tree - 1 - 1",
"child": [
{
"id": 4,
"pid": 2,
"name": "Tree - 1 - 1- 1"
}]
},
{
"id": 3,
"pid": 1,
"name": "Tree - 1 - 2"
}
]
},
{
"id": 5,
"pid": 0,
"name": "Tree - 2"
}
]
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
data2tree-1.0.2.tar.gz
(2.0 kB
view hashes)
Built Distribution
Close
Hashes for data2tree-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a2cfb65c0d32ce0aecba3ac66546d8809ad054bf66fcaad54306d1c279b1d8 |
|
MD5 | 037306fe81f57e0b4e7715edf1be1c72 |
|
BLAKE2b-256 | 68669e0fe33d2e97f73a2d648516e735b768eb263e4e61d683854d133b1ba177 |