1. Range and Xrange
Range ([Start,] stop[, step])
Range can create a list from start to stop (not included), and when used in loops, loads the list into memory at once.
Xrange ([Start,] stop[, step])
Xrange can create a generator from start to stop (not included), which, when used in a loop, does not load everything at once, but instead returns one value per call, so it always consumes very little memory and does not require significant memory space.
2. Lambda
Lambda [arg1[, arg2, ... ArgN]: expression
Lambda is an anonymous function in Python.
Func = lambda x,y:x*yfunc (#Ten
3. Map
Map (function, sequence): Executes function (item) on item in sequence, returns the list
Map (Lambda x:x+1, range (1,5))#[2, 3, 4, 5]
4. Filter
Filter (function, sequence): Executes function (item) on item in sequence, and the item that executes the result of true is composed of a list/string/ Tuple (depending on the type of sequence)
def func (x) return x>5Filter (func, Range (#[6, 7]
5. Reduce
Reduce (function, sequence, starting_value): Invokes function for the item order in the sequence and, if there is a starting_value, can also be called as an initial value
Reduce (lambda x, Y:x+y, Range (1, 101)) #5050# 1+2+3+...+100 = 5050 reduce (lambda x, Y:x+y, Range (1, 101), # 5150 # + 1+2+3+...+100 = 5150