The list map()
method calls a function for each value in a list and then outputs a new list with the modified values.
#incrementByOne
def values_list(number) {
return number + 1
}
my_list = [1, 2, 3, 4]
result = map(values_list, my_list) #returns [2, 3, 4, 5]
-
Create a function named
increment_by_one
that will multiply each number by 3. -
Use the list
map()
function to run theincrement_by_one
function through each value in the list. -
Store the new list in a variable named
new_list
andprint()
the new values.
-
The function will take a parameter with the original item being transformed and added into the new list.
-
Remember that your function must return each of the new items to be stored into the new list.