Map() function: =============== Syntax: map(function, collection/iterable) here: function: that defines the operation to apply on each element of the collection. -> map() function is used to apply a given condition/function with condition to each item of the given iterable object/collection (like: tuple, list, set etc.,) and return a map object as a result. -> map() function can be very useful for applying the same operation to all elements in a collection without using loop explicitly. Ex: Let's assume that you are managing a list of prices (in USD) of some products, and you want to convert these prices into different currency. ($1000, $200, $108, $11, $55) ==> (Rs80000, 16000, 10640, 880,...) prices_usd = [100,200,300,400,500] # global variable def convertToEuros(prices_usd): priceInEuros = prices_usd * 0.85 return priceInEuros p = tuple(map(convertToEuros,prices_usd)) print("Product prices in USD = ",prices_usd) print("Product prices in Euros = ",p) map() with lambda function: =========================== Syntax: map(lambda-function, collection) prices = [100,200,300,400,500] dicounted_prices = list(map(lambda x : x * 0.9, prices)) print(dicounted_prices) ============================================================== why use map() ============= 1) cleaner code: ================ we can avoid writing of explicit loops for transforming each items in a collection. 2) map() can improve the functional approach. Because of this the readability of the program can be improved. 3) Performance is high. Because this function faster than using a loop especially with larger data sets. Basically it was developed with C. ============================================================ reduce(): ========= Syntax: reduce(function, collection) -> used to reduce the collection into single value by applying the function on each element of the given collection. Ex: [1,3,5,7,9] ==> 1 + 3 + 5 + 7 + 9 ==> 25 Note: ===== -> to use reduce() we must import it. Syntax: from functools import reduce from functools import reduce expenses = [1000, 200, 50, 100,1500,6000] totalExpenses = reduce(lambda x,y:x+y,expenses) print(totalExpenses) Advantages: =========== 1) To make develop concise codes which can improve the readability of the program from functools import reduce expenses = [1000, 200, 50, 100,1500,6000] total = 0 # with loop for expense in expenses: total += expense print(total) # without loop total = reduce(lambda x,y:x+y,expenses) print(total) 2) Avoid the extra variables. 3) reduce() provide the flexibility to implement any complex logic.