def normalize_dict(data: Union[Dict, List, Any]):
    """
    Sort by value, while iterate over element if data is list
    """
    # if not data:
    #     return {}

    if isinstance(data, dict):
        new_data = dict()
        for key in sorted(data.keys(), key=lambda k: (len(k), k)):
            value = normalize_dict(data[key])
            if value:
                if not isinstance(value, list):
                    value = [value]
                new_data[key] = value

    elif isinstance(data, list):
        if all(isinstance(item, dict) for item in data):
            new_data = []
            for item in data:
                item = normalize_dict(item)
                if item:
                    new_data.append(item)
        else:
            new_data = [str(item).strip() for item in data if type(item) in {str, int, float} and str(item).strip()]
    else:
        new_data = [str(data).strip()]
    return new_data

    Sort by value, while iterate over element if data is list
    
vlmeval/dataset/utils/ccocr_evaluator/kie_evaluator.py