0

Can't seem to understand map function in Python.

Would like a basic explanation

27th Feb 2019, 5:09 PM
loleverytime okay
loleverytime okay - avatar
2 Respostas
+ 6
Simply this function takes two types of parameters. The first one is a function and the second is iterable(like lists, tuples...). the map function will applies the function(the parameter) to each element in the iterable and return alist of results. example : def addX(x): return x+x list1 = [1,2,3,4] list2 = map(addX,list1) #it will take the first element in the list and returns it as a parameter for addX(). and repeat that for rhe rest of the element. print(list2) Output: [2,4,6,8]
27th Feb 2019, 7:26 PM
Ali
Ali - avatar
+ 1
Such a clear and great explanation! Thanks alot!
27th Feb 2019, 7:38 PM
loleverytime okay
loleverytime okay - avatar