學習筆記
Python中兩個列表相乘
#map()函數映射求兩個列表相乘
func = lambda x,y:x*y
result = map(func,[1,2,3,4],[4,3,2,1])
list_result = list(result)
print(list_result)
運行結果
[4, 6, 6, 4]
總結
利用Python內置函數map()和lambda匿名函數可快速計算兩個列表的乘積
map 函數會根據提供的函數對指定序列做映射
學習筆記
#map()函數映射求兩個列表相乘
func = lambda x,y:x*y
result = map(func,[1,2,3,4],[4,3,2,1])
list_result = list(result)
print(list_result)
[4, 6, 6, 4]
利用Python內置函數map()和lambda匿名函數可快速計算兩個列表的乘積
map 函數會根據提供的函數對指定序列做映射