def substitute_nans(codes):
    substituted = []
    if codes:
        for code in codes:
            if isinstance(code, list):
                substituted.append(substitute_nans(code))
            elif ((not isinstance(code, float)) or (not math.isnan(code))):
                substituted.append(code)
            else:
                substituted.append('NAN')
    else:
        substituted.append(None)
    return substituted
def substitute_nans(codes):
    substituted = []
    if codes:
        for code in codes:
            if isinstance(code, list):
                substituted.append(substitute_nans(code))
            elif ((not isinstance(code, float)) or (not math.isnan(code))):
                substituted.append(code)
            else:
                substituted.append('NAN')
    else:
        substituted.append(None)
    return substituted