map,reduce,filter之python2,python3区别
来源:互联网 发布:处理数据 英文 编辑:程序博客网 时间:2024/05/21 09:46
python3里面,reduce是需要导入的。而导入的情况下,是不需要加list的,而map和filter是python自带的,这个需要加list的。
#python3版本的from functools import reducea = [1,2,3,4]print(list(map(lambda x:str(x),a)))print(list(map(str,a)))a = [str(i) for i in a]print(reduce(lambda x,y:x+y ,a))print(list(filter(lambda x:int(x)%2==0,a)))print(list(map(lambda x:int(x)%2,a)))
python2版本中,是不需要加list的,而且map,reduce,filter是自带的。使用的时候不需要加list,直接使用即可。
#python2版本的a = [1,2,3,4]print(map(lambda x:str(x),a))print(reduce(lambda x,y:x+y,a))print(filter(lambda x:x%2==0,a))
阅读全文
0 0
- map,reduce,filter之python2,python3区别
- python2 filter() map() reduce()函数基础
- python3 中的 map,reduce,filter函数
- python3中使用map,reduce和filter
- python3中的map,filter,reduce函数解析
- python3-map,filter,reduce,lambda函数
- python3 中的 map,reduce,filter函数
- python3中使用map,reduce和filter
- Python之map、reduce、filter
- Python2与Python3的区别(六):filter
- python2,3中内建函数map,reduce,filter,sorted配合lambda
- python2和python3 map函数的区别
- 如何在python3.3用 map filter reduce
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- 如何在python3.3用 map filter reduce
- Python学习笔记: Python3中map、filter、reduce函数
- python 多维数组(array)排序
- 堆和栈, 他们是什么?
- python3爬虫攻略(9):requests的使用
- [BZOJ2208][Jsoi2010]连通数(tarjan+topdp)
- C++编译链接
- map,reduce,filter之python2,python3区别
- Android---蓝牙状态值
- 单例设计模式
- Spring的声明式事务和编程式事务详解
- 本地代码上传github时,让你少走弯路
- 数据查询
- [FAQ15114]如何获取进程的native调用栈?
- python入门学习
- 给定可能包含重复的数字的集合,返回所有可能的唯一排列。