Build a Medical Data Validator - Step 44

Tell us what’s happening:

I am getting Your code raised an error before any tests could run. Please fix it and try again.

Your code so far

def validate(data):
    is_sequence = isinstance(data, (list, tuple))

    if not is_sequence:
        print('Invalid format: expected a list or tuple.')
        return False
        
    is_invalid = False
    key_set = set(
        ['patient_id', 'age', 'gender', 'diagnosis', 'medications', 'last_visit_id']
    )

    for index, dictionary in enumerate(data):
        if not isinstance(dictionary, dict):
            print(f'Invalid format: expected a dictionary at position {index}.')
            is_invalid = True
            continue

        if set(dictionary.keys()) != key_set:
            print(
                f'Invalid format: {dictionary} at position {index} has missing and/or invalid keys.'
            )
            is_invalid = True
            continue
        invalid_records = find_invalid_records(**dictionary)
        for key in invalid_records:
            value = dictionary[key]
            print(f"Unexpected format '{key}: {value}' at position {index}.")
            is_invalid = True

    if is_invalid:
        return False
        print('Valid format.')
        return True

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Medical Data Validator - Step 44

Welcome to the forum @bry254 !

Please reset this step and try again. Although the code you wrote is fine, you must have inadvertently changed something in the starting code, which will cause the tests to fail.

Happy coding!