Skip to main content

Library for transform data structures

Project description

HTL - Library for transform data structures

Example

from htl.htl import linear_to_hierarchical, hierarchical_to_linear


linear = [
    {'name': 'Lorem',       'parent': None},
    {'name': 'ipsum',       'parent': 'Lorem'},
    {'name': 'dolor',       'parent': 'ipsum'},
    {'name': 'sit',         'parent': 'dolor'},
    {'name': 'amet',        'parent': 'ipsum'},
    {'name': 'consectetur', 'parent': 'Lorem'},
    {'name': 'adipisicing', 'parent': 'consectetur'}
]

hierarchical = linear_to_hierarchical(linear)

"""
hierarchical:
{
    'name': 'Lorem',
    'children': [
            {
                'name': 'ipsum',
                'children': [
                    {
                        'name': 'dolor',
                        'children': [
                            {
                                'name': 'sit'
                            }
                        ]
                    },
                    {
                        'name': 'amet'
                    }
                ]
            },
        {
                'name': 'consectetur',
                'children': [
                    {
                        'name': 'adipisicing'
                    }
                ]
        }
    ]
}
"""
# To reverse conversion, use function hierarchical_to_linear

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htl-1.0.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

htl-1.0.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page