from typing import List
from typing import Dict


def dictify(data, keys: List, val: Dict) -> Dict:
    """Turns a flat :class:`NodeTree` dictionary into a nested dictionary.

    Helper function to generate nested dictionary from list of keys and value. 
    Calls itself recursively.
    
    Arguments:
        data (dict): A dictionary to add value to with keys.
        keys (list): A list of keys to traverse along tree and place value.
        val (dict): A value for innermost layer of nested dict.

    """
    key = keys[0]
    key = int(key) if key.isdecimal() else key.lower()
    if len(keys) == 1:
        data[key] = val
    else:
        if key in data.keys():
            data[key] = dictify(data[key], keys[1:], val)
        else:
            data[key] = dictify({}, keys[1:], val)
    return data