Linked Questions

Popular Questions

I have a list like this.

data = [{
'category': 'software', 
'code': 110, 
'actual': '["5.1.4"]', 
'opened': '2018-10-16T09:18:12Z', 
'component_type': 'update', 
'event': 'new update available', 
'current_severity': 'info', 
'details': '', 
'expected': None, 
'id': 10088862, 
'component_name': 'Purity//FA'
}, 
{
'category': 'software', 
'code': 67, 
'actual': None, 
'opened': '2018-10-18T01:14:45Z', 
'component_type': 'host', 
'event': 'misconfiguration', 
'current_severity': 'critical', 
'details': '', 
'expected': None, 
'id': 10088898, 
'component_name': 'pudc-vm-001'
}, 
{
'category': 'array', 
'code': 42, 
'actual': None, 
'opened': '2018-11-22T22:27:29Z', 
'component_type': 'hardware', 
'event': 'failure', 
'current_severity': 'warning', 
'details': ''  , 
'expected': None, 
'id': 10089121, 
'component_name': 'ct1.eth15'
}]

I want to iterate over this and get only category, component_type, event and current_severity.

I tried a for loop but it says too values to unpack, obviously.

for k, v, b, n in data:
                print(k, v, b, n) //do something

i essentially want a list that is filtered to have only category, component_type, event and current_severity. So that i can use the same for loop to get out my four key value pairs.

Or if there is a better way to do it? Please help me out.

Note: The stanzas in the list is not fixed, it keeps changing, it might have more than three stanzas.

Related Questions