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)))




  1. We have defined a list where function needs to be applied.
  2. Created a function MyFunction that takes an input variable and returns the double value of the input parameter.
  3. Calling a map function and applies the function. Here the value of each item in the list is doubled.
  4. Convert it into list and print the list. This step is optional.


Picture showing the output of the Map function in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, March 12, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250