Python 内建函数主要分为:filter() map() reduce() zip()
1.filtera = [1,2,3,4,5,6,7] print(list(filter(lambda x:x<5,a)))2.map
a = [1,2,3,4,5,6,7] print(map(lambda x:x,a)) print(list(map(lambda x:x,a))) print(list(map(lambda x:x*x,a)))
a = [1,2,3,4,5,6,7] b = [1,1,1,1,1,1,1] print(list(map(lambda x,y:x+y,a,b)))reduce
from functools import reduce print(reduce(lambda x,y:x+y,[2,3,4],1)) # (1+2)+3+4zip
zip((1,2,3),(4,5,6)) for i in zip((1,2,3),(4,5,6)): print(i) dicta = {'a':'aa','b':'bb'} dictb = zip(dicta.values(),dicta.keys()) print(dict(dictb))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)