A
A
Anton2021-09-04 15:44:42
Python
Anton, 2021-09-04 15:44:42

How to write such a condition in Python?

Greetings!
Please tell me how to write a condition, for example, there is such a code:

request = requests.get("https://site.io/api")
        request = request.json()
        for row in request["result"]:
            print(row)
The result of the execution will be the server response:
{'account': 'John', 'volume': '0'}
{'account': 'Ben', 'volume': '0'}
{'account': 'Boris', ' volume': '0'}
{'account': 'Pavel', 'volume': '0'}
How to write a condition if any of the volume parameters from the result is greater than 0 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-09-04
@boypush

if any(float(row['volume']) > 0 for row in reques['result']):
    pass

It is assumed that all elements have a volume field, and it contains an integer or fractional number, or its string representation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question