First of all to recommend a very good Python primer site, feel more than the "basic Python" and other books easier to understand, Liao Xuefeng Station, hope to have learning resources students can also communicate a lot. Here's what we learned today:
Here is a summary of some of the most distinctive functions and their applications:
1. Map
Function usage: def func (x):
.......
L=[l0,l1,l2,l3,...]% a list
Lout=map (func,l)% The value output of each element after the Func function transformation is lout
2. Reduce
Function usage: reduce (func,l) =. Func (Func (func (L0,L1), L2), L3),..
Similar iterative usage:
Reduce completes sum:
k=[1,2,3] Kout=sum (k)
def add_ (x1,x2):
Return x1+x2
Kout=reduce (Add_,k)
3, there is a very efficient calculation of the expression: A1,B1=B1,A1+B1 These two operations are simultaneous
4. Generator
In order to solve the problem that the list needs to occupy a large amount of memory space in the large-scale computation, a generator is generated in the listing generation, while the loop calculates
List-generated: H=[x*x for x in range (10)]
Generator: g= (x*x for X in range (10))
Generator output: G.next ()
5. Filter filtering function (self-proclaimed)
Filter (Func,l) func is true output otherwise does not output
6. Sorted function can be customized, which is why Python is a sort of a sharp weapon.
The default is sorted by ASCII size, in order from small to large, the machine by identifying two neighbors compared to the output of 1 is greater than the latter, 1 is the opposite of the rules to sort
Python Learning Notes