python functions reduce, filter
## reduce
>>> reduce(lambda x,y: x+y,[1,2,3,4,5])
15
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
Python higher order functions
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
Syntax for
map(function,interable...)
1 #Use map Fu ...
Posted on Tue, 03 Dec 2019 08:58:13 -0800 by DrDankWD
Python recursively lists file scripts and their anonymous functions in directories
1. Script example of recursively listing files in directory
To list the files in the directory, you can do the following: os.listdir()
In [1]: import os
In [4]: os.listdir('/root')
Out[4]:
['.tcshrc',
'.bash_history',
'.bashrc',
'ENV',
'.cache',
'.config',
'.cshrc',
'.bash_logout',
'python',
'.ssh',
'shell',
'.bash_profile',
'.i ...
Posted on Tue, 03 Dec 2019 08:46:46 -0800 by eon201
Evaluate strings to get results
Demand:
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:
1. Use Eval in JavaScript to convert strings into objects for calculation
Using Com control calculation me ...
Posted on Mon, 02 Dec 2019 04:18:42 -0800 by goaman
How do I stop a thread pool?
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.
1. ...
Posted on Thu, 28 Nov 2019 18:02:33 -0800 by uniboy86
s21day12 python notes
I. middle and high level functions
1.1 function can do return value
#Example:
def func():
print(123)
def bar():
return func
v = bar()
v()
1.2 closure
Concept: create an area for a function and maintain its own data, which can be easily called later
Application scenario:
Decorator
SQLAlchemy source code
#Example:
name = 'oldboy'
de ...
Posted on Thu, 28 Nov 2019 10:57:16 -0800 by developer
Java review note 8 - multithreading
concept
For the concept of thread and process, please refer to the following article:
Concurrent / parallel / blocking / non blocking
Multi process concept
Multithreading 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 of Java 8's new features
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
Fixedfunction - replace function in std
Original from: http://www.tanjp.com/archives/135 (immediate fix and update)
Fixed function
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
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