Lambda functions with iterables
You've used lambda functions to perform actions on a single value; now it's time to test yourself on working with iterables.
You've been provided with a list called sales_prices
containing sales prices for several items. Your goal is to use a lambda function to add tax (20%) to each value in the list.
This exercise is part of the course
Intermediate Python for Developers
Exercise instructions
- Create
add_taxes
using a lambda function that multiplies each value insales_prices
by 20%. - Create a new list called
sales_plus_tax
, by convertingadd_taxes
to a list. - Print the
sales_plus_tax
list.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
sales_prices = [29.99, 9.95, 14.50, 39.75, 60.00]
# Create add_taxes to add 20% to each item in sales_prices
add_taxes = ____(____, ____)
# Create the updated list, sales_plus_tax
sales_plus_tax = ____(____)
# Print the new list with updated values
print(____)