+ 1
Does map works like to add values in list?
if so, then how can we call that list? because map store the value in function. how can we call that later in code?
1 Answer
+ 2
Definitely!
To use map, you need 2 parameters. The first is the function you are using within the list, and the actual list itself. If you want to store that into the result of the map as a list into a variable, you could just wrap the map around a list function and assign to a variable (which could also be the same variable containing the list that the map is looping through).
For example:
def multtwo(x):
return x * 2
spam = [5,3,4,2]
foo = list(map(multtwo,spam))