Best-Effort Cleanup

Medium ⏱ 12 min 45% acceptance ★★★★★ 4.6
Write cleanup_all(tasks) that calls every zero-argument callable in tasks, ignoring any exception each may raise, and returns the count of tasks that succeeded. Cleanup routines must never abort their siblings.

Examples

Example 1
Input
cleanup_all([ok_fn, failing_fn, ok_fn])
Output
2
Explanation

The failing task is swallowed; both good ones ran.

Constraints

  • Every task must be attempted.
  • Count successes only.

Topics

Exception Handlingsuppression

Companies

UberAirbnb

Hints

Hint 1

try/except Exception inside the loop.

Hint 2

Increment only in the try path (or use else).

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