>>> reduce(lambda x,y: x+y,[1,2,3,4,5])
Please watch carefully. Can you see how it works? Draw a picture:
Remember how map works? Forgot? Look at the code:
>>> list1 = [1,2,3,4,5,6,7,8,9]
>>> list2 = [9,8,7,6,5,4,3,2,1]
>>> map(lambda x,y: x+y, list1,list2)
[10, 10, 10, 10, 10, 10, 10, 10, 10]
Posted on Thu, 05 Dec 2019 17:49:19 -0800 by MMeticulous
Higher order function: simply speaking, one function can receive another function as a parameter. Such a function is called a higher order function
The map function will map the specified sequence according to the function provided, that is to say, it will act on the specified sequence
1 #Use map Fu ...
Posted on Tue, 03 Dec 2019 08:58:13 -0800 by DrDankWD
1. Script example of recursively listing files in directory
To list the files in the directory, you can do the following: os.listdir()
In : import os
In : os.listdir('/root')
Posted on Tue, 03 Dec 2019 08:46:46 -0800 by eon201
Calculate a string in C x to get the result.
For example: "1 + 2 + 66 + 33"
The number in the string can be changed, and the number of times to accumulate (here lazy limit to accumulate) can be changed.
Ideas / solutions:
Using Com control calculation me ...
Posted on Mon, 02 Dec 2019 04:18:42 -0800 by goaman
The java.util.concurrent.ExecutorService interface in the Java Concurrency Toolkit defines methods for thread pool task submission, getting thread pool status, and thread pool stop.
In JDK 1.8, the shutdown(), shutdown Now (), shutdown() + awaitTermination(long timeout, TimeUnit unit) methods are generally used for thread pool stopping.
Posted on Thu, 28 Nov 2019 18:02:33 -0800 by uniboy86
I. middle and high level functions
1.1 function can do return value
v = bar()
Concept: create an area for a function and maintain its own data, which can be easily called later
SQLAlchemy source code
name = 'oldboy'
Posted on Thu, 28 Nov 2019 10:57:16 -0800 by developer
For the concept of thread and process, please refer to the following article:
Concurrent / parallel / blocking / non blocking
Multi process concept
The above article code uses python, but all concepts and principles are the same;
It needs to be emphasized that threads in Java can be executed in parallel on multi-c ...
Posted on Wed, 27 Nov 2019 03:52:06 -0800 by Barb54
Method reference and constructor reference
As we have known about lambda expressions, there are generally two parts. The left side of the arrow operator (- >) is the parameter list of the lambda body, and the right side is the lambda body. In some cases, the operations in the lambda body can be written in another way, which is shorter.It can ...
Posted on Mon, 25 Nov 2019 06:18:50 -0800 by mnewhart
Original from: http://www.tanjp.com/archives/135 (immediate fix and update)
Functors are the basis of many new features of C + +, such as lambda expressions. However, the std::function provided by STL takes into account too many situations and its performance is not high. Then, the optimization is done, and ...
Posted on Sat, 23 Nov 2019 09:44:28 -0800 by pvechi
The application of Lambda expression
Call the Collection.sort() method, compare the two employees by custom sorting (first by age, the same age by name), and pass the Lambda as a parameter
List<Employee> employees = Arrays.asList(
new Employee("Zhang San", 18 ,9999.99),
new Employee("Li Si", 50, 5555.99),
Posted on Tue, 19 Nov 2019 06:39:01 -0800 by ednark