笔记13-filter,map,reduce内置类的使用

# python2 filter是内置函数python3 filter 是内置类# filte

笔记13-filter,map,reduce内置类的使用

# python2 filter是内置函数  python3 filter 是内置类
# filter两个参数,函数和可迭代对象
# filter对可迭代对象进行过滤,过滤的结果是filter对象(依然是可迭代对象)
ages = [12, 23, 30, 17, 16, 22, 19]
agesFilter = filter(lambda ele: ele > 18, ages)adult = list(agesFilter)
print(adult)# map内置类的使用
lists = [1, 2, 3, 4, 5, 6]
i = map(lambda element: element + 3, lists)
print(list(i))# reduce类的使用
from functools import reducetuples = (1, 2, 3, 4, 5, 6)
tuplesReduce = reduce(lambda x, y: x + y, tuples)
print(tuplesReduce)listDicts = [{"name": "胡勇", "age": 21, "height": 180},{"name": "卢雯婷", "age": 18, "height": 158},{"name": "喵喵", "age": 2, "height": 10},]
print(reduce(lambda x, y: x + y['age'], listDicts, 0))

发布者:admin,转转请注明出处:http://www.yc00.com/web/1691002195a483658.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信