【Python 笔记】神奇的匿名函数
来源:互联网 发布:淘宝网秋冬运动套装 编辑:程序博客网 时间:2024/05/20 03:04
Write a function, factory, that takes a number as its parameter and returns another function.The returned function should take an array of numbers as its parameter, and return an array of those numbers multiplied by the number that was passed into the first function.In the example below, 5 is the number passed into the first function. So it returns a function that takes an array and multiplies all elements in it by five.Translations and comments (and upvotes) welcome!
Examplefives = factory(5) # returns a function - fivesmy_array = [1, 2, 3]fives(my_array) # returns [5, 10, 15]
Python的神奇之处在于使用了匿名函数使得原本需要def两个函数的模块只写了一个函数,并且只用了一行~
def factory(x): return lambda l: [x*i for i in l] # Good Luck!
0 0
- 【Python 笔记】神奇的匿名函数
- Python的匿名函数
- Python学习笔记-匿名函数
- Python学习笔记: Python匿名函数lambda的使用
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python的lambda匿名函数
- Python匿名函数的使用
- Python学习笔记--匿名函数lambda
- python 中神奇的函数参数传递
- Python的内置函数和匿名函数
- python 学习笔记---匿名函数 装饰器 偏函数
- 【Python学习笔记】函数式编程:匿名函数lambda
- [Algorithm]Maze Prim算法与A*寻路算法(中)
- poj 2983 Is the Information Reliable?(差分约束)
- java的几种对象(PO,VO,DAO,BO,POJO)解释
- 传智播客168期JavaEE就业班(第五天 xml约束与解析)
- Hadoop中空间数据的存储(二)
- 【Python 笔记】神奇的匿名函数
- 如何处理大量数据并发操作
- 如何优化tomcat配置(从内存、并发、缓存4个方面)优化
- Xutils HttpUtils上传文件的实现
- 查看安卓apk源码
- java学习心得——数据展示之javabeen配置和jstl配置
- RMQ板子 求区间最大最小值
- 15 装饰着模式
- 【题解】2016 BUPT Winter Training #2