From 9eb292c0bf80bcf0ec914dbd33e10a1803b99905 Mon Sep 17 00:00:00 2001 From: abhishekrahul93 Date: Fri, 21 Nov 2025 09:26:18 +0100 Subject: [PATCH] Completed Lambda, Map, Reduce, Filter lab --- ...-lambda-map-reduce-filter-checkpoint.ipynb | 493 ++++++++++++++++++ lab-python-lambda-map-reduce-filter.ipynb | 219 +++++++- 2 files changed, 693 insertions(+), 19 deletions(-) create mode 100644 .ipynb_checkpoints/lab-python-lambda-map-reduce-filter-checkpoint.ipynb diff --git a/.ipynb_checkpoints/lab-python-lambda-map-reduce-filter-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-lambda-map-reduce-filter-checkpoint.ipynb new file mode 100644 index 0000000..eaa1340 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-lambda-map-reduce-filter-checkpoint.ipynb @@ -0,0 +1,493 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": {}, + "source": [ + "# Lab | Lambda Functions, Map, Reduce, Filter" + ] + }, + { + "cell_type": "markdown", + "id": "6f8e446f-16b4-4e21-92e7-9d3d1eb551b6", + "metadata": {}, + "source": [ + "Objective: The objective of this lab is to help students gain familiarity with using anonymous lambda functions and map, reduce, and filter methods in Python." + ] + }, + { + "cell_type": "markdown", + "id": "0120f101-3f9a-444c-84b9-a10a990a5f95", + "metadata": {}, + "source": [ + "Lambda functions, map, reduce, and filter are all related to functional programming in Python. \n", + "\n", + "**Lambda functions** are anonymous functions in Python, which means that they do not need to be defined with a name. They are typically used for short, one-line functions that are not going to be used elsewhere in the code. \n", + "\n", + "Lambda functions can take any number of arguments, but they can only contain a single expression. They are often used in combination with other built-in functions like map, reduce, and filter to perform operations on lists or other iterables." + ] + }, + { + "cell_type": "markdown", + "id": "7afb4d9e-63a9-4326-87f1-a0915769721c", + "metadata": {}, + "source": [ + "**Map** is a function that applies a given function to every element of a list, returning a new list with the transformed values. It's a useful way to apply the same operation to every element of a list, without having to write a for loop.\n", + "\n", + "**Reduce** is a function that applies a given function to the first two elements of a list, then applies the same function to the result and the next element, and so on, until it has reduced the list to a single value. It's useful for performing cumulative operations like summing or multiplying a list of numbers.\n", + "\n", + "**Filter** is a function that takes a function and a list, and returns a new list containing only the elements of the original list for which the function returns True. It's a useful way to selectively extract elements from a list based on a certain condition." + ] + }, + { + "cell_type": "markdown", + "id": "053ee1bc-59fa-4cf8-9191-916b6cdc5811", + "metadata": {}, + "source": [ + "All of these concepts can be used to make your code more concise and expressive, especially when working with lists or other iterables. They are also useful in data manipulation tasks, such as cleaning and transforming data in a pandas DataFrame. By practicing with these concepts in the lab, you will gain a better understanding of how to use them in a variety of programming tasks." + ] + }, + { + "cell_type": "markdown", + "id": "65df3710-f236-4818-9a4f-43bfd53cad7c", + "metadata": {}, + "source": [ + "## Challenge 1" + ] + }, + { + "cell_type": "markdown", + "id": "0e704740-6ac4-49d0-b25b-960cf8511a04", + "metadata": {}, + "source": [ + "In this Challenge we will use the following data, which is a list of bank transactions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "08463071-9351-4d49-8d29-4fcb817fb177", + "metadata": {}, + "outputs": [], + "source": [ + "transactions = [(-1200, 'debit'), (2500, 'credit'), (-100, 'debit'), (850, 'credit'), (-250, 'debit'), (1500, 'credit'), (-300, 'debit'), (5000, 'credit'), (-850, 'debit'), (1000, 'credit')]" + ] + }, + { + "cell_type": "markdown", + "id": "ae7d88f0-a8e7-4f74-98d3-802306bdcf07", + "metadata": {}, + "source": [ + "### Exercise 1" + ] + }, + { + "cell_type": "markdown", + "id": "16796011-a618-499a-a57f-4ca61d0a77e7", + "metadata": {}, + "source": [ + "Create a new list called credits that includes all of the debit transactions from the list transactions.\n", + "\n", + "Use the filter() function to create a new list called debits." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0781335d-39cf-403d-b86a-ca908a09fe55", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Credits: [(2500, 'credit'), (850, 'credit'), (1500, 'credit'), (5000, 'credit')]\n", + "Debits: [(-1200, 'debit'), (-100, 'debit'), (-250, 'debit'), (-300, 'debit')]\n" + ] + } + ], + "source": [ + "# -----------------------------------------\n", + "# FULL CODE FOR CHALLENGE 1 (Copy & Run)\n", + "# -----------------------------------------\n", + "\n", + "# Bank transactions list\n", + "transactions = [\n", + " (-1200, 'debit'),\n", + " (2500, 'credit'),\n", + " (-100, 'debit'),\n", + " (850, 'credit'),\n", + " (-250, 'debit'),\n", + " (1500, 'credit'),\n", + " (-300, 'debit'),\n", + " (5000, 'credit')\n", + "]\n", + "\n", + "# -------------------------------\n", + "# Exercise 1: Filter debits & credits\n", + "# -------------------------------\n", + "\n", + "# Credits: all transactions where transaction type == 'credit'\n", + "credits = list(filter(lambda x: x[1] == 'credit', transactions))\n", + "\n", + "# Debits: all transactions where transaction type == 'debit'\n", + "debits = list(filter(lambda x: x[1] == 'debit', transactions))\n", + "\n", + "print(\"Credits:\", credits)\n", + "print(\"Debits:\", debits)\n" + ] + }, + { + "cell_type": "markdown", + "id": "37ca34af-7f87-44f2-a45d-1a1e2ef8c194", + "metadata": {}, + "source": [ + "### Exercise 2" + ] + }, + { + "cell_type": "markdown", + "id": "546c5aa2-6f16-4285-9c47-0f788b23552c", + "metadata": {}, + "source": [ + "Create a new list that includes all of the debit transactions from the list transactions, sorted in descending order by amount.\n", + "\n", + "- Use the previously created debits list.\n", + "- Define a lambda function called sort_descending that takes two tuples and returns True if the transaction amount of the first tuple is greater than the transaction amount of the second tuple.\n", + "- Use the sorted() function with sort_descending and debits to create a new list." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "25073469-7258-4fc6-b0a0-ef8ea57688fe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(-100, 'debit'), (-250, 'debit'), (-300, 'debit'), (-1200, 'debit')]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# We assume that 'transactions' and 'debits' are already defined from Exercise 1.\n", + "# If not, include them here:\n", + "\n", + "transactions = [\n", + " (-1200, 'debit'),\n", + " (2500, 'credit'),\n", + " (-100, 'debit'),\n", + " (850, 'credit'),\n", + " (-250, 'debit'),\n", + " (1500, 'credit'),\n", + " (-300, 'debit'),\n", + " (5000, 'credit')\n", + "]\n", + "\n", + "# Exercise 1 (needed for Exercise 2)\n", + "debits = list(filter(lambda x: x[1] == 'debit', transactions))\n", + "\n", + "# -------------------------------------------\n", + "# Exercise 2 — Sort debits in descending order\n", + "# -------------------------------------------\n", + "\n", + "# Lambda function for sorting comparison\n", + "sort_descending = lambda x: x[0] # sort by transaction amount\n", + "\n", + "# Create the sorted list (descending order)\n", + "sorted_debits_desc = sorted(debits, key=sort_descending, reverse=True)\n", + "\n", + "sorted_debits_desc\n" + ] + }, + { + "cell_type": "markdown", + "id": "bee57a6e-19a3-4708-9b70-3b41a215353f", + "metadata": {}, + "source": [ + "## Challenge 2: Interest Calculation" + ] + }, + { + "cell_type": "markdown", + "id": "4e7c9f00-7c48-4c39-9de1-14db7fc468eb", + "metadata": {}, + "source": [ + "### Exercise 1" + ] + }, + { + "cell_type": "markdown", + "id": "3500df4c-91bd-4f8f-9ffe-4d6a51460bc6", + "metadata": {}, + "source": [ + "Write Python code to take a list of bank account balances, and returns a new list containing the balance after one year of interest has been added. Use the map function to apply this function to the list of bank accounts, and take an interest rate of 0.05." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1de9d03-f029-4e2e-9733-ae92e3de7527", + "metadata": {}, + "outputs": [], + "source": [ + "# create list of bank account balances\n", + "balances = [100, 50, -25, 1000, -10]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2f253b7e-5300-4819-b38f-9fc090554f51", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[105.0, 52.5, -26.25, 1050.0, -10.5]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balances = [100, 50, -25, 1000, -10]\n", + "\n", + "# Interest rate\n", + "interest_rate = 0.05\n", + "\n", + "# Use map + lambda to calculate new balances\n", + "updated_balances = list(map(lambda x: x * (1 + interest_rate), balances))\n", + "\n", + "updated_balances\n" + ] + }, + { + "cell_type": "markdown", + "id": "6a515b75-8ccb-4ee3-9dc0-f36d72ac66a0", + "metadata": {}, + "source": [ + "### Exercise 2" + ] + }, + { + "cell_type": "markdown", + "id": "7022779a-7611-428b-8f7d-138e923a63b8", + "metadata": {}, + "source": [ + "Write Python code to take a list of bank account dictionaries, each containing the account balance and interest rate, and returns a new list of dictionaries containing the balance after one year of interest has been added. Use the map function to apply this function to the list of bank accounts." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69e24c3b-385e-44d6-a8ed-705a3f58e696", + "metadata": {}, + "outputs": [], + "source": [ + "accounts = [\n", + " {'balance': 1000, 'interest_rate': 0.02},\n", + " {'balance': 2000, 'interest_rate': 0.01},\n", + " {'balance': 500, 'interest_rate': 0.03},\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "0906a9b0-d567-4786-96f2-5755611b885e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'balance': 1020.0, 'interest_rate': 0.02},\n", + " {'balance': 2020.0, 'interest_rate': 0.01},\n", + " {'balance': 515.0, 'interest_rate': 0.03}]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code goes here\n", + "accounts = [\n", + " {'balance': 1000, 'interest_rate': 0.02},\n", + " {'balance': 2000, 'interest_rate': 0.01},\n", + " {'balance': 500, 'interest_rate': 0.03},\n", + "]\n", + "\n", + "# Use map + lambda to calculate new balances after 1 year of interest\n", + "updated_accounts = list(map(lambda acc: {\n", + " 'balance': acc['balance'] * (1 + acc['interest_rate']),\n", + " 'interest_rate': acc['interest_rate']\n", + "}, accounts))\n", + "\n", + "updated_accounts\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "69788c08-90c5-4c15-be3d-55ac4a963fe2", + "metadata": {}, + "source": [ + "## Challenge 3: Balance Reduction" + ] + }, + { + "cell_type": "markdown", + "id": "81536227-379c-461f-b564-6695957bd0c1", + "metadata": {}, + "source": [ + "### Exercise 1" + ] + }, + { + "cell_type": "markdown", + "id": "1006852a-42fc-4aae-bc0a-c771a94f6b2d", + "metadata": {}, + "source": [ + "Write Python code to take the new list of bank account balances (balances list after applying an interest_rate of 0.05, result of Challenge 1 Exercise 1), and print the total amount of negative balances. Use filter and reduce function." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "6284dbd3-e117-411e-8087-352be6deaed4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Negative balances: [-26.25, -10.5]\n", + "Total negative balance: -36.75\n" + ] + } + ], + "source": [ + "from functools import reduce\n", + "\n", + "# your code goes here\n", + "from functools import reduce\n", + "\n", + "# balances after applying 5% interest \n", + "updated_balances = [105.0, 52.5, -26.25, 1050.0, -10.5]\n", + "\n", + "# Step 1: Filter negative balances\n", + "negative_balances = list(filter(lambda x: x < 0, updated_balances))\n", + "\n", + "# Step 2: Reduce to get total negative balance\n", + "total_negative = reduce(lambda x, y: x + y, negative_balances)\n", + "\n", + "print(\"Negative balances:\", negative_balances)\n", + "print(\"Total negative balance:\", total_negative)\n" + ] + }, + { + "cell_type": "markdown", + "id": "3926594f-3204-4de3-a6bf-bd87069a82cc", + "metadata": {}, + "source": [ + "### Exercise 2" + ] + }, + { + "cell_type": "markdown", + "id": "6149139b-43db-473b-a10e-8bff9a38dcbf", + "metadata": {}, + "source": [ + "Write a Python function called calculate_balance that takes a bank account dictionary as an argument and returns the remaining balance after subtracting all the withdrawals.\n", + "\n", + "Then, use the map function and the calculate_balance function to apply it to the list accounts. This should give you a list of remaining balances after all the withdrawals have been subtracted." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "da2264b5-298e-4b45-99df-852b94e90d15", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[650, 1600, 275]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accounts = [\n", + " {'balance': 1000, 'withdrawals': [100, 50, 200]},\n", + " {'balance': 2000, 'withdrawals': [300, 100]},\n", + " {'balance': 500, 'withdrawals': [50, 100, 75]},\n", + "]\n", + "\n", + "# your code goes here\n", + "\n", + "# Given accounts list\n", + "accounts = [\n", + " {'balance': 1000, 'withdrawals': [100, 50, 200]},\n", + " {'balance': 2000, 'withdrawals': [300, 100]},\n", + " {'balance': 500, 'withdrawals': [50, 100, 75]},\n", + "]\n", + "\n", + "# Step 1 — Define calculate_balance()\n", + "def calculate_balance(account):\n", + " balance = account['balance']\n", + " withdrawals = account['withdrawals']\n", + " remaining = balance - sum(withdrawals)\n", + " return remaining\n", + "\n", + "# Step 2 — Use map() to calculate remaining balances\n", + "remaining_balances = list(map(calculate_balance, accounts))\n", + "\n", + "remaining_balances\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d8465df-3f38-4012-a0a0-c113161e508b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/lab-python-lambda-map-reduce-filter.ipynb b/lab-python-lambda-map-reduce-filter.ipynb index 96c9781..eaa1340 100644 --- a/lab-python-lambda-map-reduce-filter.ipynb +++ b/lab-python-lambda-map-reduce-filter.ipynb @@ -94,12 +94,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "0781335d-39cf-403d-b86a-ca908a09fe55", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Credits: [(2500, 'credit'), (850, 'credit'), (1500, 'credit'), (5000, 'credit')]\n", + "Debits: [(-1200, 'debit'), (-100, 'debit'), (-250, 'debit'), (-300, 'debit')]\n" + ] + } + ], "source": [ - "# your code goes here" + "# -----------------------------------------\n", + "# FULL CODE FOR CHALLENGE 1 (Copy & Run)\n", + "# -----------------------------------------\n", + "\n", + "# Bank transactions list\n", + "transactions = [\n", + " (-1200, 'debit'),\n", + " (2500, 'credit'),\n", + " (-100, 'debit'),\n", + " (850, 'credit'),\n", + " (-250, 'debit'),\n", + " (1500, 'credit'),\n", + " (-300, 'debit'),\n", + " (5000, 'credit')\n", + "]\n", + "\n", + "# -------------------------------\n", + "# Exercise 1: Filter debits & credits\n", + "# -------------------------------\n", + "\n", + "# Credits: all transactions where transaction type == 'credit'\n", + "credits = list(filter(lambda x: x[1] == 'credit', transactions))\n", + "\n", + "# Debits: all transactions where transaction type == 'debit'\n", + "debits = list(filter(lambda x: x[1] == 'debit', transactions))\n", + "\n", + "print(\"Credits:\", credits)\n", + "print(\"Debits:\", debits)\n" ] }, { @@ -124,12 +160,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "25073469-7258-4fc6-b0a0-ef8ea57688fe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[(-100, 'debit'), (-250, 'debit'), (-300, 'debit'), (-1200, 'debit')]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code goes here" + "# We assume that 'transactions' and 'debits' are already defined from Exercise 1.\n", + "# If not, include them here:\n", + "\n", + "transactions = [\n", + " (-1200, 'debit'),\n", + " (2500, 'credit'),\n", + " (-100, 'debit'),\n", + " (850, 'credit'),\n", + " (-250, 'debit'),\n", + " (1500, 'credit'),\n", + " (-300, 'debit'),\n", + " (5000, 'credit')\n", + "]\n", + "\n", + "# Exercise 1 (needed for Exercise 2)\n", + "debits = list(filter(lambda x: x[1] == 'debit', transactions))\n", + "\n", + "# -------------------------------------------\n", + "# Exercise 2 — Sort debits in descending order\n", + "# -------------------------------------------\n", + "\n", + "# Lambda function for sorting comparison\n", + "sort_descending = lambda x: x[0] # sort by transaction amount\n", + "\n", + "# Create the sorted list (descending order)\n", + "sorted_debits_desc = sorted(debits, key=sort_descending, reverse=True)\n", + "\n", + "sorted_debits_desc\n" ] }, { @@ -169,12 +243,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "2f253b7e-5300-4819-b38f-9fc090554f51", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[105.0, 52.5, -26.25, 1050.0, -10.5]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code goes here" + "balances = [100, 50, -25, 1000, -10]\n", + "\n", + "# Interest rate\n", + "interest_rate = 0.05\n", + "\n", + "# Use map + lambda to calculate new balances\n", + "updated_balances = list(map(lambda x: x * (1 + interest_rate), balances))\n", + "\n", + "updated_balances\n" ] }, { @@ -209,12 +302,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "0906a9b0-d567-4786-96f2-5755611b885e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[{'balance': 1020.0, 'interest_rate': 0.02},\n", + " {'balance': 2020.0, 'interest_rate': 0.01},\n", + " {'balance': 515.0, 'interest_rate': 0.03}]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code goes here\n" + "# your code goes here\n", + "accounts = [\n", + " {'balance': 1000, 'interest_rate': 0.02},\n", + " {'balance': 2000, 'interest_rate': 0.01},\n", + " {'balance': 500, 'interest_rate': 0.03},\n", + "]\n", + "\n", + "# Use map + lambda to calculate new balances after 1 year of interest\n", + "updated_accounts = list(map(lambda acc: {\n", + " 'balance': acc['balance'] * (1 + acc['interest_rate']),\n", + " 'interest_rate': acc['interest_rate']\n", + "}, accounts))\n", + "\n", + "updated_accounts\n", + "\n" ] }, { @@ -243,14 +363,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "6284dbd3-e117-411e-8087-352be6deaed4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Negative balances: [-26.25, -10.5]\n", + "Total negative balance: -36.75\n" + ] + } + ], "source": [ "from functools import reduce\n", "\n", - "# your code goes here" + "# your code goes here\n", + "from functools import reduce\n", + "\n", + "# balances after applying 5% interest \n", + "updated_balances = [105.0, 52.5, -26.25, 1050.0, -10.5]\n", + "\n", + "# Step 1: Filter negative balances\n", + "negative_balances = list(filter(lambda x: x < 0, updated_balances))\n", + "\n", + "# Step 2: Reduce to get total negative balance\n", + "total_negative = reduce(lambda x, y: x + y, negative_balances)\n", + "\n", + "print(\"Negative balances:\", negative_balances)\n", + "print(\"Total negative balance:\", total_negative)\n" ] }, { @@ -273,10 +415,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "da2264b5-298e-4b45-99df-852b94e90d15", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[650, 1600, 275]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "accounts = [\n", " {'balance': 1000, 'withdrawals': [100, 50, 200]},\n", @@ -284,8 +437,36 @@ " {'balance': 500, 'withdrawals': [50, 100, 75]},\n", "]\n", "\n", - "# your code goes here\n" + "# your code goes here\n", + "\n", + "# Given accounts list\n", + "accounts = [\n", + " {'balance': 1000, 'withdrawals': [100, 50, 200]},\n", + " {'balance': 2000, 'withdrawals': [300, 100]},\n", + " {'balance': 500, 'withdrawals': [50, 100, 75]},\n", + "]\n", + "\n", + "# Step 1 — Define calculate_balance()\n", + "def calculate_balance(account):\n", + " balance = account['balance']\n", + " withdrawals = account['withdrawals']\n", + " remaining = balance - sum(withdrawals)\n", + " return remaining\n", + "\n", + "# Step 2 — Use map() to calculate remaining balances\n", + "remaining_balances = list(map(calculate_balance, accounts))\n", + "\n", + "remaining_balances\n", + "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d8465df-3f38-4012-a0a0-c113161e508b", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -304,7 +485,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.6" } }, "nbformat": 4,