Posts

Showing posts from July, 2020

Introduction to the map() Function: Behind the Scenes

Image
👋 Welcome In this tutorial you will learn how to work with the built-in  map()  function. Let’s begin. 🔹 Purpose and Syntax The  map()  function applies a function that is passed as argument to every element of an iterable. 💡 Tip:  An iterable is an object capable of returning its members one at a time (for example: lists, tuples, dictionaries, and strings). They can be used in for loops. The  map()  function takes two parameters (in this order): The function that we want to apply to each item of the iterable. The iterable. 🔸 Example If we have this line of code: map(f, [1, 2, 3, 4, 5]) Where  f  is a function that is already defined in the program, this is what happens behind the scenes: The function  f  is called with the first element of the iterable as the argument (in this case, 1). That function call is completed and a value is returned (if the function returns a value). The same process is r...