lambda表达式返回一个函数对象
map(function,sequence),把sequence中的值逐个传给function,返回一个包含函数执行结果的list
例子:
squares = list(map(lambda x: x**2, range(10)))
squares值是
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
相当于:
squares = [x**2 for x in range(10)]
也相当于:
>>> squares = []>>> for x in range(10):
... squares.append(x**2)