百度举报网站,如何用家用电脑做网站,高德地图导航放弃重庆,公司网站页面1、什么是高阶函数#xff1f;
高阶函数是指将函数作为参数传入。就是高阶函数
2、高阶函数有哪些#xff1f;
map 映射函数 print(list(map(lambda x:x*x,range(1,11))))
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]print(list(map(lambda x:st…1、什么是高阶函数
高阶函数是指将函数作为参数传入。就是高阶函数
2、高阶函数有哪些
map 映射函数 print(list(map(lambda x:x*x,range(1,11))))
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]print(list(map(lambda x:str(x),[1,2,3,4,5])))
[1, 2, 3, 4, 5]filter 过滤函数 print(list(filter(lambda x:x%30,range(1,101))))
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]print(list(filter(lambda x:x %2 0,range(1,11))))
[2, 4, 6, 8, 10]print(list(filter(lambda x:x%2,range(1,11))))
[1, 3, 5, 7, 9]reduce 函数累积求值需要导入from functools import reduce n [1,2,3,4,5,6,7]from functools import reduceprint(reduce(lambda n,y:n*y,n))
5040
sorted 排序函数 list1[7, -8, 5, 4, 0, -2, -5]print(sorted(list1,keylambda x:max(list1)-x1 if x 0 else x))
[4, 5, 7, 0, -2, -5, -8]print(list(sorted(list1,keylambda x:(x0,abs(x)))))
[4, 5, 7, 0, -2, -5, -8]list1 [bob,about,Zoo,Credit]print(sorted(list1,keylambda x:x.lower()))
[about, bob, Credit, Zoo]