INNER CODE UNIT · Python

diff_remove_empty

O-X-L/ansible-opnsense · plugins/module_utils/helper/main.py:5

def diff_remove_empty(diff: dict, to_none: bool = False) -> dict:
    """
        Cleans a dictionary by removing empty lists or sub-dictionaries.

        :param diff: The original diff dictionary.
        :param to_none: If True, sets empty values to None instead of removing the key.
        :return: A cleaned version of the diff dictionary.
    """
    d = diff.copy()
    for k in diff:
        if len(diff[k]) == 0:
            if to_none:
                d[k] = None

            else:
                d.pop(k)

    return d

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…