Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python map function

# The map function applies a function to every item in a list,
# and returns a new list.

numbers =  [0, -1, 2, 3, -4]

def square_func(n):
    return n*n
 
new_numbers = list(map(square_func, numbers))
#new_numbers: [0, 1, 4, 9, 16]
 
PREVIOUS NEXT
Tagged: #python #map #function
ADD COMMENT
Topic
Name
9+5 =