Skip to main content

Lambda, Map, and Filter in Python


Lambda: Lambda functions are known as the anonymous functions in Python. This kind of functions are declared without any name.

  • Can accept any number of argument. 
  • Restricted to only a single expression. 
  • Used only one-time.
  • Lambda function is used when you need a function for a short period of time. 
Basic syntax: 
lambda arguments : expression

Example:

Map: Map is a built-in function that takes a function object and iterable list (list/dictionary) as its parameter.
Basic syntax:
map (function_object, iterable_1, iterable_2, ... )

Few examples of Map in python:

Filter: It works similar way like map. The difference is it makes a new list from the element in the list that satisfy some condition. In case of of parameters, it takes a function and one iterable.
Basic syntax:
filter (function, iterable)

Normally used with lambda functions. Example is given below:



Comments

Post a Comment