map,reduce,filter之python2,python3区别
2017-10-30 11:10
645 查看
python3里面,reduce是需要导入的。而导入的情况下,是不需要加list的,而map和filter是python自带的,这个需要加list的。
python2版本中,是不需要加list的,而且map,reduce,filter是自带的。使用的时候不需要加list,直接使用即可。
#python3版本的 from functools import reduce a = [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))
相关文章推荐
- Python中Lambda, filter, reduce and map 的区别
- python中的高阶函数map(),reduce(),filter()的区别
- python中filter(),map()和reduce()的区别
- 基于python的-map(),reduce(),filter()函数的使用与区别
- python中高阶函数filter,map,reduce三者的区别
- python常用函数(zip,map,filter,reduce)
- Python中的Map, Filter和Reduce
- Python一些特殊用法(map、reduce、filter、lambda、列表推导式等)
- 【python】filter,map,reduce和lambda函数介绍
- Python特殊语法:filter、map、reduce、lambda [转]
- Python的lambda, filter, reduce 和 map简介
- 【转】Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda [转]
- python3--map,reduce,filter,zip
- Python中的map、reduce和filter浅析
- Python内置函数之map()、reduce()、filter()函数
- Python特殊语法:filter、map、reduce、lambda
- python的lambda、filter、map、reduce、zip函数
- Python中的map、reduce和filter浅析
- Python【map、reduce、filter】内置函数使用说明