Articles → Python → Map Function In Python
Map Function In Python
Purpose
Example
mylist = [1,2,3,4,5]
def MyFunction(var):
return var*2
print(list(map(MyFunction, mylist)))
- We have defined a list where function needs to be applied.
- Created a function MyFunction that takes an input variable and returns the double value of the input parameter.
- Calling a map function and applies the function. Here the value of each item in the list is doubled.
- Convert it into list and print the list. This step is optional.
Click to Enlarge