map函数

# map(function, iterbale)  返回map对象,可list转化,不可tuple转化
# 输入 iterable对象数量没有限制 vs 输出对象取决于最短的输入iterable。
ret = map(lambda x, y: x + y, [1, 3, 5, 7, 9, 20], [2, 4, 6, 8, 10, 10])
print(list(ret))

# Lambda 接收的变量数量 == iterable 对象的数量
ret = map(lambda x: x ** 2, [1, 2, 3, 4, 5])
print(list(ret))

def square(x):
    return x**x
ret = map(square, [1, 2, 3, 4, 5])  # square  int  float str 都可以
print(list(ret))
[3, 7, 11, 15, 19, 30]
[1, 4, 9, 16, 25]
[1, 4, 27, 256, 3125]
posted @ 2020-12-09 08:25  疯狂列表推导式  阅读(110)  评论(0编辑  收藏  举报