python3--map,reduce,filter,zip

# coding=utf-8

pool1 = [1,2,3,4]
pool2 = ['a','b','c','d']

## map()
r1 = list(map(lambda x: x*2,pool1))
print(r1) #[2, 4, 6, 8]

## reduce()
from functools import reduce
r2 = reduce(lambda x,y: x*y,pool1,100)
print(r2) #2400

## filter()
r3 = list(filter(lambda x: x>2,pool1))
print(r3) #[3, 4]

## zip()
r4 = list(zip(pool1,pool2))
print(r4) #[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章