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 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 data2tree-1.0.2.tar.gz.
File metadata
- Download URL: data2tree-1.0.2.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7bf06bb893eab29e62f640c8f78babf8c4c8972fbc47fe4b6de77ab74f754a0
|
|
| MD5 |
2bf4d7881578728fef853af2643e34d9
|
|
| BLAKE2b-256 |
6ab9eb84d983d0511b3157e3e3b41a28f4b42c8a1ca7c0fdced18f237cd6e0c8
|
File details
Details for the file data2tree-1.0.2-py3-none-any.whl.
File metadata
- Download URL: data2tree-1.0.2-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33a2cfb65c0d32ce0aecba3ac66546d8809ad054bf66fcaad54306d1c279b1d8
|
|
| MD5 |
037306fe81f57e0b4e7715edf1be1c72
|
|
| BLAKE2b-256 |
68669e0fe33d2e97f73a2d648516e735b768eb263e4e61d683854d133b1ba177
|