14.Python built-in functions ⼆

⼀. Lamda anonymous function

In order to address the needs of ⽽ ⼀ some simple design ⼀ sentence function

lambda table above shows the anonymous function. Using def do not need to declare, ⼀ words can declare the functions ⼀

grammar:

Function name = lambda parameter: Return value

note:

1. The parameters of the function may have a plurality of spaced plurality Use commas. Parameters

2. anonymous function no matter how complex. ⼀ ⾏ can only write, and returns the data directly after the end of logic

3. normal function return value and ⼀ like, can be any data type

Anonymous function is not to say ⼀ given no name. Screen for individual cases from the former variable is ⼀ a function name. Said he was anonymous because we pass

__Name__ view over when there is no name. ⼀ system called lambda. Using the tone when nothing special.

Use like a normal function call can be

⼆. sorted()

Sort function.

语法: sorted(Iterable, key=None, reverse=False)

Iterable: iterables

key: collation (sorting function), each element in the sorted ⼀ inner iteration object will be passed to this function

Parameter function operation based on a result of the number of feed ⾏ sort reverse:. Flashback whether True:. Flashback, False: positive sequence

Using a combination of function and

Using the combination and lambda

Three. Fifilter ()

Filter function

Syntax: fifilter (. Function Iterable)

function:. Use the filter function to automatically pass to the element in the iterable fifilter then the function.

According to function returning True or False to determine whether to keep this data

Iterable: iterables

 

Four. Map ()

Mapping function

Syntax: map (function, iterable) can perform while mapping iterables each element were taken ⼀ YES.

function

Calculation List Zhongping ⽅ each element, and returns the new list

Rewrite lambda

Calculating the position of the same in both lists and data

V. recursive

Using the present transfer function in the function chest upwards. Recursion is

The depth of recursion in python from the largest to 998

Recursive to apply it:

We can use the recursion to traverse a variety of tree, such as our folder system can be accessed using recursion to traverse the

All files in the folder

VI. ⼆ points Find

⼆分查找. 每次能够排除掉⼀半的数据. 查找的效率非常⾼. 但是局限性比较⼤. 必须是有

序序列才可以使⽤⼆分查找

要求: 查找的序列必须是有序序列.

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/xuweng/p/12178415.html