BaşlayınÜcretsiz Başlayın

Use of lambda() with map()

The map() function in Python returns a list of the results after applying the given function to each item of a given iterable (list, tuple etc.). The general syntax of map() function is map(fun, iter). We can also use lambda functions with map(). Refer to slide 5 of video 1.7 for general help of map() function with lambda().

In this exercise, you'll be using lambda function inside the map() built-in function to square all numbers in the list.

Bu egzersiz

Big Data Fundamentals with PySpark

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Print my_list which is available in your environment.
  • Square each item in my_list using map() and lambda().
  • Print the result of map function.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Print my_list in the console
print("Input list is", ____)

# Square all numbers in my_list
squared_list_lambda = list(____(lambda x: ____, my_list))

# Print the result of the map function
print("The squared numbers are", ____)
Kodu Düzenle ve Çalıştır