def convert_keys_to_variable_names(dict_):
    """
    Change keys in dict to comply with PEP8 for variable names.

    Keys are converted to all lower case and spaces replaced with underscores.

    Parameters
    ----------
    dict_ : :class:`dict`
        Dictionary the keys should be renamed in

    Returns
    -------
    new_dict : :class:`dict`
        Dictionary the keys have been renamed in


    .. versionadded:: 0.2.1

    """
    new_dict = dict()
    for key, value in dict_.items():
        new_key = key.replace(' ', '_').lower()
        if isinstance(value, dict):
            new_dict[new_key] = convert_keys_to_variable_names(dict_[key])
        else:
            new_dict[new_key] = dict_[key]
    return new_dict