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
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-0.0.1.tar.gz
(2.0 kB
view hashes)
Built Distribution
Close
Hashes for data2tree-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa31da62cd1384715d7996a3d756c3850c1fd5b3db4db64f2451c3fbef5c50b7 |
|
MD5 | 122697c6a6f981b1c3d9e38c917c36c0 |
|
BLAKE2b-256 | 4943801cd6fda66e69860cb10e504bdd642c4bab33596a66df6cbbfba8bcd57c |