The main contents of today
1. lambda anonymous function
syntax:
the lambda parameters: return value
can not perform complex operations can only write a single line
2. sorted () function ordering
sorted(iterable, key =None ,reverse=false)
sorted (iterables, key = None, reverse = False)
= LST [1,3,23,6,4,34,23,12,9] lst.sort () is a list inside a #sort method Print (LST) the sorted (LST) # built-in function, a back to you the new list, the new list is sorted. (And dic.frokeys ()) the same effect, Print (LST)
Sort.
1. iterables
2. key = function. Collation
3. reverse. Whether reverse
Principle: Each element in the interior will be sorted iteration object passed to this function key parameters, sorted according to the output of the function. For example: the length can be sorted list of strings
3. filter () function filters
filter (function, iterable) is dealt a iterator
Principle: The iterator objects each element is passed to a function, and is determined according to the function returns True or False if this data is preserved
1. The function returns True or False
2. iterables
4. map () function mapping
map (function, iterable) is a processed iterator
Principle: can be mapped to the iterator object in each element, respectively, and then performs function
1. Function
2 iterables
5 . Recursive
calls itself.
DEF FUNC ():
FUNC ()
FUNC ()
Uses: traverse the tree
difficult: the need to find a bad think the law is not good read.
Traversing the tree structure Import OS filePath = "D: \ Sylar \ python_workspace" DEF Read (filePath, n-): IT = the os.listdir (filePath) # open the folder for EL in IT: # get path fp = os.path .join (filePath, el) # to get the absolute path if os.path.isdir (fp): # determine whether the folder Print ( "\ t" the n-*, EL) the Read (fp, the n-+ 1) is # continue to read the folder contents of the internal recursive entrance. the else: Print ( "\ t" the n-*, EL) # recursive export read (filePath, 0)
6. dichotomy
end pinch head takes an intermediate. Constantly changing the left and right. Indirectly change the center.
Query efficiency is very high, but the limitations of relatively large, must be ordered sequence before you can use binary search