def replace_nones ( dict_or_list ) : def replace_none_in_value ( value ) : if isinstance ( value , basestring ) and value . lower ( ) == "none" : return None return value items = dict_or_list . iteritems ( ) if isinstance ( dict_or_list , dict ) else enumerate ( dict_or_list ) for accessor , value in items : if isinstance ( value , ( dict , list ) ) : replace_nones ( value ) else : dict_or_list [ accessor ] = replace_none_in_value ( value )
python for none values replace
Update a dict or list in place to replace none string values with Python None .
def replace_nones(dict_or_list):
    """Update a dict or list in place to replace
    'none' string values with Python None."""

    def replace_none_in_value(value):
        if isinstance(value, basestring) and value.lower() == "none":
            return None
        return value

    items = dict_or_list.iteritems() if isinstance(dict_or_list, dict) else enumerate(dict_or_list)

    for accessor, value in items:
        if isinstance(value, (dict, list)):
            replace_nones(value)
        else:
            dict_or_list[accessor] = replace_none_in_value(value)