Reputation: 133
I am using below code, if i am sending "89" as pressure value and temperature as "Null" in this case it is showing "value not processed". I want it to show message of value processed and also for value not processed what condition i can use in below code.
payload = [{'id': 'Room1',
'pressure': {'metadata': {}, 'type': 'Number', 'value': '89'},
'temperature': {'metadata': {}, 'type': 'Number', 'value': 'Null'},`'type': 'RoomTest'}]`
attrs = ['temperature', 'pressure']
x = (len(payload))
Flag=True
for i in range(x):
for j in attrs:
y = payload[i][j]['value']
if '' in y or 'Null' in y:
Flag=False
if Flag:
print("successfully processed")
else:
print("successfully not processed")
Any help will be appreciated.Thanks
Upvotes: 0
Views: 828
Reputation: 532418
I would skip both the flag and the explicit for
loop, and use any
instead.
if any(p[j]['value'] in ('', 'Null') for p in payload for j in attrs):
print("successfully not processed")
else:
print("successfully processed")
Upvotes: 1