Build a Medical Data Validator - Step 44

No. Look at the outer loop again. What are you already getting from that loop?

You have been trying to get key, val, and index from invalid_records, but invalid_records only has which of those?

Oh, I am getting the index

Yes; index is available from the outer loop. What else can you get from the outer loop? And what can you get from invalid_records?

I can get the index, but not the key or value

You have established that you can get the index from the outer loop.

And you already said that ‘paitient_id’ from invalid_records is a key in the dictionary, right?

So, you just need to get the value for any keys in the invalid_records list.

How can you do that?

Yes, the index and dictionary are created with the outer loop.

Is it by printing the values?

At the bottom of the script, you are calling validate() and passing in medical_records as the argument. The parameter for validate() is data, a reference to medical_records. Inside the medical_records list, there are dictionary objects. The outer loop in getting those dictionary objects in the loop variable dictionary. You can use that to get the value of the key(s) you get from invalid_records.

I think I mostly understand what you are saying, but I don’t fully know what you want me to do.

Now that you know this code is inside another loop, how does it make sense to change this code? Please give it a try. Start with what you know you can get from invalid_records.

Do you have any further questions about implementing the instructions?

We aren’t able to divine what you do or do not understand.

Yes, sorry. I know I need to figure the final solution out on my own. But I have no idea what to do regarding fixing my code.

What have you learned so far in this discussion?

 print(f"Unexpected format '{key}: {val}' at position {index}.")

Use this print line as a guide. What variables do you need to accomplish this?

I need the key, val, and index variables.

Review the code you’ve written so far, from the start of the function.

Can you find any of those variables?

I get the index from line 71, and the key and values are in the medical_records dictionary.

This is line 71

    for index, dictionary in enumerate(data):

It’s true that dictionary has vey/value pairs inside it, but I don’t see those variables ready to print here. key and val are not yet defined.

I do see another of the variables that you need. Do you see it?

print(f"Unexpected format '{key}: {val}' at position {index}.")

Are the keys on line 77? Also, are the remaining variables inside the ‘for’ loop on line 71?

No. The variable key or val is not created yet.

What variables are created in this line

for index, dictionary in enumerate(data):

Index and dictionary.