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.
Bu egzersiz
Intermediate Python for Developers
kursunun bir parçasıdırEgzersiz talimatları
- Apply the lambda function to each value in the
colleagueslist, saving ascleaned. - Convert the map object to a list, saving as
cleaned_list.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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)