Git Product home page Git Product logo

tree-based-data-structure's Introduction

Tree Based Data Structure

Algorithm in Python that generates a tree-based data structure (dictionary) from a list of lists of data.

Tree image

From data stored in a list of lists, generate a hierarchical tree-based data structure (a dictionary). The lists can have different number of elements. The "final" elements (leaves) will always be stored in a list (even if it is an empty list or a single element list).

The algorithm obtains, for example, [2] from [1].

[1]

data = [
         ['living_being'     , 'animal'    , 'fish'          , 'bream'         ], 
         ['living_being'     , 'animal'    , 'fish'          , 'bass'          ], 
         ['living_being'     , 'plant'      , 'pine'          , 'pinnus_pinnea'], 
         ['living_being'     , 'bacteria'  , 'lactobacillus'                   ], 
         ['living_being'     , 'plant'      , 'oak'           , 'quercus_ilex' ], 
         ['living_being'     , 'animal'    , 'mollusk'       , 'snail'         ], 
         ['artificial_object', 'vehicle'   , 'car'                             ], 
         ['artificial_object', 'vehicle'   , 'moto'                            ], 
         ['artificial_object', 'instrument', 'guitar'                          ], 
         ['natural_object'                                                     ],
       ]

[2]

result = {

    'living_being': {

        'animal': {
            'fish':    ['bream', 'bass'], 
            'mollusk': ['snail']
        }, 

        'plant': {
            'pine':  ['pinnus_pinnea'], 
            'oak':   ['quercus_ilex']
        }, 

        'bacteria': ['lactobacillus']
    }, 

    'artificial_object': {
        'vehicle':    ['car', 'moto'], 
        'instrument': ['guitar']
    }, 

    'natural_object': []

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.