python 函数式

map

list(map(str,range(10)))
Out[1]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
def mul(x):
    return x*x
a=list(range(10))
list(map(mul,a))
Out[18]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

reduce

from functools import reduce
a=list(range(1,10))
def add(x,y):   
    return x+y
a=list(range(10))

reduce(add,a)
Out[13]: 45

filter

a=list(range(10))

def filt(x):
    return x % 2==1
b=filter(filt,a)

list(b)
Out[24]: [1, 3, 5, 7, 9]
posted @   luoganttcc  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示