I have a dictionary as shown below:
x = {
"Student": [
{
"tags": {
"name": "Alex",
"class": "Biology",
"gender": "male",
},
"Nationality": "",
"Test Score": 10.0,
"Exam Score": 70.0,
},
{
"tags": {
"id": "A123",
"height": "170",
"age": "15",
},
"Nationality": "",
"Test Score": 20.0,
"Exam Score": 80.0,
},
],
}
I would like to obtain the Test score and exam score for the data schema above for which has a nested dictionary with key 'tag' has a the key of "id","height" and "age"
So the expected value should be "Test Score"=20.0 and "Exam Score"=80.0
I have tried the below implementation but it seems to check for only the first value in the 'Student' list (of lenght 2), but i need it to check for all the items in the list (in this case two items).
search_tag = ["id", "height", "age"]
val_list = []
if all([t in search_tag for t in x["Student"][0]["tags"].keys()]):
val_list.append(x["Student"][0]["Test Score"])
val_list.append(x["Student"][0]["Exam Score"])