今天刚发现 Python 简单的递归用 reduce 实现感觉蛮简洁的

2023-01-13 15:55:05 +08:00
 wuwukai007
2913 次点击
所在节点    Python
8 条回复
h0099
2023-01-13 15:57:56 +08:00
恭喜阁下已经入门了 FP (函数式编程)思维
eccstartup
2023-01-13 16:07:42 +08:00
不然呢
zhy0216
2023-01-13 16:11:49 +08:00
python lambda 不能做 iife (因为缩进语法原因?)
一点小遗憾
JasonLaw
2023-01-13 16:38:25 +08:00
@zhy0216 #3 什么是“python lambda 不能做 iife”?
h0099
2023-01-13 20:44:47 +08:00
#3 @zhy0216 可以吧
https://pythonsimplified.com/everything-you-need-to-know-about-python-lambda-functions/
> Another way you can invoke the Lambda function is through Immediately Invoked Function Expression (IIFE). However, this is not a recommended use of calling lambda expression. You don’t see this method being used anywhere. I have mentioned this for informational purposes only.
> >>> print((lambda x: x**2)(5))
> 25

https://elfi-y.medium.com/python-lambda-%CE%BB-6c62a5427913
> We can invoke them directly in Immediately Invoked Function Expressions (IIFE) like:
> (function (a, b) {return a + b })(1, 2); // 3
> ((a,b) => (a+b))(1, 2); // 3
julyclyde
2023-01-16 09:00:34 +08:00
reduce 是不是那个什么“柯里化”什么偏函数之类的
NoOneNoBody
2023-01-16 12:10:05 +08:00
python 一些内置函数,性能还不如表达式,当然前者简洁和阅读性强一些
不懂源码,只感觉 python 的循环表达式比较神奇,看上去只是循环,却比一段循环代码高效很多
stonesirsir
2023-01-17 15:22:34 +08:00
为啥看不到了呢?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/908714

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX