Articles → Python → Map Function In Python

Map Function In Python



mylist = [1,2,3,4,5]

def MyFunction(var):
    return var*2

print(list(map(MyFunction, mylist)))

  1. We have defined a list where a 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 applying the function. Here the value of each item in the list is doubled
  4. Convert it into a list and print the list. This step is optional


Picture showing the output of the Map function in python

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


Your Email Id  
Query/FeedbackCharacters remaining 250