【发布时间】:2012-03-24 08:35:23
【问题描述】:
现在,我开始学习 haskell,在学习的同时,我尝试在 Python 中实现我从中学到的一些想法。但是,我发现这具有挑战性。您可以在 Haskell 中编写一个函数,该函数将另一个函数作为参数,并返回相同的函数,但它的参数顺序颠倒了。可以在 Python 中做类似的事情吗?例如,
def divide(a,b):
return a / b
new_divide = flip(divide)
# new_divide is now a function that returns second argument divided by first argument
你能用 Python 做到这一点吗?
【问题讨论】:
-
我认为您可以使用 *args 然后 reverse() 该参数列表...或类似的东西。
标签: python functional-programming