Lambda statement |
Used to create a short single-line anonymous function Namevaluestr(value) Equivalent to Print_assign(namevalue):
STR(value)
Lambda requires a parameter, followed only by a single expression as the body of the function, and the value of the expression is returned by the new function. Note that even the print statement cannot be used in lambda form, only expressions are used. >>> Ftwice = Lambda s:s*2 >>> Ftwice (2) 4 Again, as the Make_repeater function creates a new function object at run time, and returns it. |
Map () function |
From Itera,iterb ... To remove the corresponding element in the application map
Map (f, Itera, iterb, ...)
Built-in functions often used with iterators.
Returns a list containing F (itera[0], iterb[0]), F (itera[1] , iterb[1]), F (itera[2], iterb[2]), ....
map (f, iterable)基本上等于[f(x) for x in iterable]
But in a plural case different: >>> List1 = [11,22,33] >>> list2 = [44,55,66] >>> list3 = [77,88,99]
Map () only does the in-column operation >>> def ABC (A, B, c): ... return a*10000 + b*100 + C ... >>> Map (ABC,LIST1,LIST2,LIST3) [114477, 225588, 336699] The list parsing does is the Cartesian product >>> [ABC (A,B,C) for a in List1 for B in List2 for C in List3] [114477, 114488, 114499, 115577, 115588, 115599, 116677, 116688, 116699, 224477, 224488, 224499, 225577, 225588, 225599, 2 26677, 226688, 226699, 334477, 334488, 334499, 335577, 335588, 335599, 336677, 336688, 336699] Equivalent to result = [] For a in List1: For B in List2: For C in List3: Result.append (ABC (ABC)) |