from typing import OrderedDict


def merge_default(config):
    """ Merge the values of the DEFAULT item into the other items.
    
        Merge a dictionary that has an item with a "DEFAULT" key,
        if that item is itself a dictionary, then merge that
        item's subitems with all the other items in the dictionary
        that are also themselves dictionaries.

        The purpose is to mimic the behaviour of the [DEFAULT]
        sections of .ini or .conf files when using .json or .yaml
        files, or when using OrderedDict or dict data structures.

        Parameters
        ----------
        config : dict or OrderedDict

            The dictionary that is to have its "DEFAULT" key merged
            with the other keys.

        Returns
        -------
        OrderedDict or dict

            The merged version of the dictionary as an OrderedDict,
            or the original config (be it a dict or an OrderedDict)
            if it had no "DEFAULT" key to begin with, or it was not
            a dict or an OrderedDict.
    """
    if isinstance(config, dict) and "DEFAULT" in config:
        default = config["DEFAULT"]
        merged_config = OrderedDict()
        for item in config:
            if item != "DEFAULT":
                if isinstance(config[item], dict):
                    merged_item = default.copy()
                    merged_item.update(config[item])
                    merged_config[item] = merged_item
                else:
                    merged_config[item] = config[item]
        return merged_config
    else:
        return config