0
Can't seem to understand map function in Python.
Would like a basic explanation
2 ответов
+ 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]
+ 1
Such a clear and great explanation! Thanks alot!