Part1:Lambda, Map , Reduce and Filter functions🚩 confused where to use them?😕🤔

Sai Prakash
2 min readMay 22, 2021

Whenever you start your Data science journey you try to pick a programming language to code ,and regarding it most people choose python.

Python language consists of many functions and libraries ,which try to save our time .From them lamda,map,reduce and filter functions are quite popular.

These functions are quite simple ,But most people often gets confused and they forget to when to use them. So here is your friend who will help you to get things clear.

Lambda():

lambda function simply is an ananomous function which is used without any name.

In python we usually define any function using def keyword.

So whenever we want to use function without defining anything, we use lambda .

Syntax:

lambda arguments: expression
  1. arguments are the values/parameters we try to pass ,
  2. expression is the operation we are trying to define

Examples:

>>> sum= lambda a,b: a+b
>>> sum(4,3)
output:
7

In above example we take a,b as arguments and we were trying to add those parameters then we are storing it into sum variable ,so whenever we pass any parameters into sum function we will get sum of those values.

Map():

Map function mainly used to reduce the code writing work, It mainly takes two parameters into it, they are:

  1. function() : a function to be executed on iterable object
  2. Iterables: iterables like lists,which needed to get mapped to function specified

Syntax:

map(fun, iter)

Examples:

numbers1 = [4,5,6]

numbers2 = [1,2,3]

result = map(lambda x, y: x-y, numbers1, numbers2)

print(list(result))

output:[3,3,3]

In above example we have passed lambda function and two iterable list objects, two lists are mapped to lambda function and result is stored in result variable

lastly I would thank you all for going through my blog,although it’s just a basic functions but I think it would be a great help to all the newbies out there who are not clear in those functions .

And please leave your comments so that I could be improving myself and try to give my best — — — — — — — — — — Sai prakash.

--

--

Sai Prakash

I write a lot of boring stuff about data , read it if you're bored.