Review a generated payment summary

from map, filter and reduce
Python 3.14 advanced 8 min 4 issues to find

Review this generated lazy pipeline for correctness, boundary handling, readability, and data movement.

Parse order_id,amount,status CSV lines, retain paid rows, and return their amount total and count.

Python
from functools import reduce

def summarize_payments(lines):
    cleaned = map(str.strip, lines)
    rows = map(lambda line: line.split(","), cleaned)
    paid_rows = filter(lambda row: row[2] == "paid", rows)
    amounts = map(lambda row: float(row[1]), paid_rows)

    def append_amount(acc, amount):
        return acc + [amount]

    paid_amounts = reduce(append_amount, amounts, [])
    total = reduce(lambda acc, amount: acc + amount, paid_amounts)
    return {
        "total": round(total, 2),
        "count": len(paid_amounts),
    }

generated code is illustrative, not from any one model

Open in playground
Report an error