Python map() Built in Function
The map() function in Python executes a specified function for each item in an iterable. The item is sent to the function as a parameter. The map() function returns a map object, which is an iterator that yields the results of applying the function to each item. The map object can be converted into a list, tuple, set, or other collection type. Here are some examples of using map() function in Python: Using map() with a single iterable # This example applies the len() function to each element of a list and returns a list of lengths words = ["apple", "banana", "cherry"] lengths = list(map(len, words)) print(lengths) # Output: [5, 6, 6] Using map() with multiple iterables # This example applies the pow() function to two lists of numbers and returns a list of powers base = [2, 3, 4] exponent = [1, 2, 3] powers = list(map(pow, base, exponent)) print(powers) # Output: [2, 9, 64] Using map() with lambda functions # This example uses a lambda function to squ...