描述:
map()是 Python 內(nèi)置的高階函數(shù)寓搬,它接收一個函數(shù) f 和一個 list褥影,并通過把函數(shù) f 依次作用在 list 的每個元素上,得到一個新的 list 并返回礼预。
實例:
a = map(lambda x:x*x,[0,1,2,3,4,5,6,7,8,9])
print a
如果你熟悉列表解析的話超营,可以寫成這樣:
a = map(lambda x:x*x,[i for i in range(10)])
print a
得到的結(jié)果是:
[0,1, 4, 9, 16, 25, 36, 49, 64, 81]