Jan-11-2022, 05:18 PM
I have a list of dictionaries and in case if some dictionary has empty key I want to remove it completely from the list. In my example,
I need to remove all third block because column3 is empty.
I need to remove all third block because column3 is empty.
a = [
{
"type": "some.type2",
"payload": {
"column1": "12345",
"column2": "description",
"column3": 98
}
},
{
"type": "some.type2",
"payload": {
"column1": "12345",
"column2": "description",
"column3": 180
}
},
{
"type": "some.type2",
"payload": {
"column1": "12345",
"column2": "description",
"column3": ""
}
}
]This is my code but is not removing and I think it's because of json structurea = [d for d in payload if "" not in d.values()] print(type(a)) <class 'list'>Does anyone knows how can I solve it?
