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)