Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Intermediate Python for Developers

Cursus bekijken

Oefeninstructies

  • Apply the lambda function to each value in the colleagues list, saving as cleaned.
  • Convert the map object to a list, saving as cleaned_list.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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)
Code bewerken en uitvoeren