Map () is a Python built-in high-order function that receives a function f and a list, and then, by putting the function f on each element of the list in turn, gets a new list and returns. The following article mainly introduces the use of the map () function in Python, the need for friends can refer to the following
Objective
In Python there is a function map (), which is a bit tall on the feel. This article will give you a detailed introduction to the Python map () function used in the relevant content, share it for everyone to reference the study, the following words do not say, come together to see the detailed introduction:
Maybe you've seen Google's most lucrative paper:
"Mapreduce:simplified Data processing on Large Clusters"
Google's MapReduce paper says: Our abstraction are inspired by the map and reduce primitives present in Lisp and many other functio NAL languages.
This phrase refers to the origins of the MapReduce idea, which roughly means that MapReduce is inspired by the built-in function map and reduce in functional languages such as Lisp.
So what exactly does map () do?
In fact, the map () function is the mapping relationship of a dataset to another dataset, and the middle does not decrease or add elements. So in Python, the map () function simply takes the elements of multiple list objects out of order, and then puts them into the function to manipulate them and calculate the results. It is a parallel relationship and does not reduce the element.
As in the following example:
#python 3. 6 #蔡军生 #http://blog.csdn.net/caimouse/article/details/51749579 # def sum (x, y): return x + y list1 = [1, 3, 5, 7] List2 = [2, 4, 6, 8] result = Map (sum, List1, list2) print ([x for x in result])
The output results are as follows:
[3, 7, 11, 15]
Similarly, the idea of map function can be used to the cluster server, that is, to cut a lot of data, and then put each piece of data into different computers for parallel processing, and are the same mapping relationship of the calculation, the number of data has not increased or decreased. Then the processed data is then lumped together for the reduce process.
How does the reduce () function in Python work? We can learn from this article.
Summarize