def _normalize ( obj ) : if isinstance ( obj , list ) : return [ _normalize ( item ) for item in obj ] elif isinstance ( obj , dict ) : return { k : _normalize ( v ) for k , v in obj . items ( ) if v is not None } elif hasattr ( obj , 'to_python' ) : return obj . to_python ( ) return obj
python how to normalize a list of dictionaries
Normalize dicts and lists
def _normalize(obj):
    """
    Normalize dicts and lists

    :param obj:
    :return: normalized object
    """
    if isinstance(obj, list):
        return [_normalize(item) for item in obj]
    elif isinstance(obj, dict):
        return {k: _normalize(v) for k, v in obj.items() if v is not None}
    elif hasattr(obj, 'to_python'):
        return obj.to_python()
    return obj