def flatten_dictionary(dictionary, separator=':', flattened_dict=None, parent_string=''):
    "\n    Flattens nested dictionary into a single dictionary:\n        {'hello': {'world': 1,\n                   'moon': 2}}\n    becomes:\n        {'hello:world': 1,\n         'hello:moon': 2}\n\n    Uses recursion to flatten as many layers as exist in your dictionary.\n\n    :param dictionary: nested dictionary you wish to flatten.\n    :param flattened_dict: (used for recursion) current flattened dictionary to add to\n    :param parent_string: (used for recursion) current key string to use as prefix for\n    :return: flattened dictionary\n    :type dictionary: dict\n    :type flattened_dict: dict\n    :type parent_string: str\n    :rtype: dict\n    "
    if (flattened_dict is None):
        flattened_dict = {}
    for (k, v) in dictionary.items():
        if parent_string:
            full_key = '{0}{1}{2}'.format(parent_string, separator, k)
        else:
            full_key = k
        if isinstance(v, dict):
            _ = flatten_dictionary(v, flattened_dict=flattened_dict, parent_string=full_key)
        else:
            flattened_dict[full_key] = v
    return flattened_dict
Flattens nested dictionary into a single dictionary:
    {'hello': {'world': 1,
               'moon': 2}}
becomes:
    {'hello:world': 1,
     'hello:moon': 2}

Uses recursion to flatten as many layers as exist in your dictionary.

:param dictionary: nested dictionary you wish to flatten.
:param flattened_dict: (used for recursion) current flattened dictionary to add to
:param parent_string: (used for recursion) current key string to use as prefix for
:return: flattened dictionary
:type dictionary: dict
:type flattened_dict: dict
:type parent_string: str
:rtype: dict
def flatten_dictionary(dictionary, separator=':', flattened_dict=None, parent_string=):
    "\n    Flattens nested dictionary into a single dictionary:\n        {'hello': {'world': 1,\n                   'moon': 2}}\n    becomes:\n        {'hello:world': 1,\n         'hello:moon': 2}\n\n    Uses recursion to flatten as many layers as exist in your dictionary.\n\n    :param dictionary: nested dictionary you wish to flatten.\n    :param flattened_dict: (used for recursion) current flattened dictionary to add to\n    :param parent_string: (used for recursion) current key string to use as prefix for\n    :return: flattened dictionary\n    :type dictionary: dict\n    :type flattened_dict: dict\n    :type parent_string: str\n    :rtype: dict\n    "
    if (flattened_dict is None):
        flattened_dict = {}
    for (k, v) in dictionary.items():
        if parent_string:
            full_key = '{0}{1}{2}'.format(parent_string, separator, k)
        else:
            full_key = k
        if isinstance(v, dict):
            _ = flatten_dictionary(v, flattened_dict=flattened_dict, parent_string=full_key)
        else:
            flattened_dict[full_key] = v
    return flattened_dict