Given a dictionary,
data = { '1234': {'jid':1341, 'msg':'' , 'status':0}, '5678': {'jid':1342, 'msg':'' , 'status':1}, '1112': {'jid':1343, 'msg':'' , 'status':0}, '1314': {'jid':1344, 'msg':'' , 'status':1} }
Using Python, what is the most optimal way to check if all status
values are 1?
The way I am trying to do is to iterate through the dictionary and set a flag to 0 if at least one of the status
values is 0.
Advertisement
Answer
You can use the all
function and iterate over the values of your dictionary:
>>> all(x['status'] == 1 for x in data.values()) False