Process What You Can, Report the Rest

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.5
Write convert_amounts(rows) that converts a list of strings to floats, returning a tuple (converted, failed) where converted holds the successful floats in order and failed holds the original strings that raised ValueError. Batch jobs must not die on the first bad record.

Examples

Example 1
Input
convert_amounts(['10.5', 'oops', '3'])
Output
([10.5, 3.0], ['oops'])
Explanation

Two rows convert; the bad one is reported, not fatal.

Constraints

  • Preserve order in both lists.
  • Catch ValueError only.

Topics

Exception Handlingpartial failure

Companies

AmazonFlipkartSalesforce

Hints

Hint 1

One try/except inside the loop.

Hint 2

Append to the right list in each branch.

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