Lambda functions with iterables
You've used lambda functions on single values - now let's apply them to entire lists! This is where lambda functions really shine: when you need the same operation on every item.
In this task, you'll process a list of colleague names using a lambda function applied to the entire list.
This exercise is part of the course
Intermediate Python for Developers
Exercise instructions
- Apply the lambda function to each value in the
colleagueslist, saving ascleaned. - Convert the map object to a list, saving as
cleaned_list.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
colleagues = ["Sarah Martinez", "Michael Chen", "Emily Brown"]
# Apply the lambda function to each colleague's name
cleaned = ____(lambda x: x.replace(" ", "_").lower(), ____)
# Convert map object to list
cleaned_list = ____(____)
print(cleaned_list)