Fleet Health Checks with any() and all()

Medium ⏱ 12 min 55% acceptance ★★★★☆ 4.4
Each vehicle is a dict with 'fuel' (0-100) and 'engine_ok' (bool). Write fleet_status(vehicles) returning a tuple (all_ready, any_critical) where a vehicle is *ready* when engine_ok and fuel >= 20, and *critical* when fuel < 5. Use all() and any() with generator expressions.

Examples

Example 1
Input
fleet_status([{'fuel': 50, 'engine_ok': True}, {'fuel': 3, 'engine_ok': True}])
Output
(False, True)
Explanation

The second vehicle is below 20 fuel (not ready) and below 5 (critical).

Constraints

  • Use generator expressions, not intermediate lists.
  • Empty fleet: all() is True, any() is False — accept those defaults.

Topics

Lambda & Functionalany/all

Companies

UberOlaTesla

Hints

Hint 1

all(cond(v) for v in vehicles).

Hint 2

Two separate generator expressions keep it readable.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.