时间:2021-07-01 10:21:17 帮助过:23人阅读
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 object
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) ) )
li = [1, 2, 3, 4, 5, 6, 7, 8, 9] # 自增1 def add1(x): return x + 1 # 自减1 def red1(x): return x - 1 # 平方 def square(x): return x ** 2 def map_test(func, l): tl = [] for i in l: tl.append(func(i)) return tl # 调用上面定义的函数 print(map_test(add1, li)) print(map_test(red1, li)) print(map_test(square, li))
li = [1, 2, 3, 4, 5, 6, 7, 8, 9] def map_test(func, l): tl = [] for i in l: tl.append(func(i)) return tl print(map_test(lambda x: x + 1, li)) print(map_test(lambda x: x - 1, li)) print(map_test(lambda x: x ** 2, li))
以上就是Map的详细内容,更多请关注Gxl网其它相关文章!