+ 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?

10th Feb 2018, 3:50 AM
AMAN AGARWAL
AMAN AGARWAL - avatar
1 Antwort
+ 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))
10th Feb 2018, 4:22 AM
Faisal
Faisal - avatar