Stage 3

🔹 Topic #40 | Stage 3 | Python | 📊 Level: Intermediate | 🌐 Coding5s.com
Concept: Higher-Order Functions (map(), filter())
Dataset detected: NO

The Tech Lead Persona: In Stage 3, the AI assumes the role of a busy Tech Lead delegating tasks before a production deployment. This simulates a real agile work environment, establishing urgency and shifting the focus from ‘learning from scratch’ to ‘contributing to an existing codebase.’

Hello team, I need you to adjust and optimize these functions using map() and filter() before tonight’s production deployment; review the TODO blocks carefully.
Challenge 1 (Score 3):
Objective: Filter a list of dictionaries to obtain only the approved transactions and then extract and convert their amounts to decimal format (float).
Expected Output:
Plaintext
$150.5
$200.0
$99.99
$45.0

Reading Before Writing: The ‘Incomplete Code’ structure is intentional. In the industry, developers spend more time reading legacy code than writing new code. By embedding TODO and Hint comments, the student is trained to read the surrounding context, understand data structures, and inject their solution seamlessly into a pre-existing function.

Incomplete Code:
Python
def process_transactions():
    transactions = [
        {"id": 1, "amount": "150.50", "status": "approved"},
        {"id": 2, "amount": "200.00", "status": "approved"},
        {"id": 3, "amount": "50.00", "status": "rejected"},
        {"id": 4, "amount": "99.99", "status": "approved"},
        {"id": 5, "amount": "45.00", "status": "approved"}
    ]

    # TODO: Missing extraction and filtering of amounts. Currently returns an empty list.
    # Hint: Use filter() to get dictionaries with "approved" status and map() for the amounts.
    approved_amounts = []

    for amount in approved_amounts:
        print(f"${amount}")

process_transactions()
Scroll to Top