map(func, *iterables) --> map object
Make an iterator that computes the function using arguments from
each of the iterables. Stops when the shortest iterable is exhausted.
map(func, *iterables) --> map objectfunc 逻辑简单lambda匿名函数,逻辑复杂需自拟; *iterables 可迭代对象 map函数所得的结果也是一个可迭代对象,但是只能遍例一次.?
?
例: 自定义函数模拟内置函数map,列表自增减1及平方
内置函数map实现列表自增减1及平方
li = [1, 2, 3, 4, 5, 6, 7, 8, 9 ] # 自增1 print (list(map( lambda x: x + 1 , li))) # 自减1 print (list(map( lambda x: x - 1 , li))) # 平方 print ( list( map( lambda x: x ** 2 , li) ) )声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84909
Map
python3.6
阅读:38次