def build_dictionary(tree, dictionary, current_node, code, tree_type=0):
    """Traverses the tree and builds the code dictionary. Must be used in 
    `traverse_tree` function.

    The tree must be built by the `build_tree` function or in the same form.
    Performs depth-first search operation recursively, builds code dictionary.
    Assigns `0` to the left node and `1` to the right node by default. If you want to
    change this to the exact opposite, use `tree_type=1`

    Args:
        tree (dict): Code tree that is built with `build_tree` function
        dictionary (dict): Code dictionary, initially an empty dict
        current_node (str): The node which the function currently tests
        code (list): 

    Returns:
        dict: Huffman code dictionary
    """
    if tree_type == 1:
        codes = range(1, -1, -1)
    else: 
        codes = range(2)

    if current_node in list(tree.keys()):
        for (child, i) in zip(tree[current_node][1:], codes):
            code.append(f'{i}')
            build_dictionary(tree, dictionary, child[0], code, tree_type)
            code.pop()
    else:
        code_str = "".join(code)
        dictionary[current_node] = code_str

    return dictionary