You may want to use recursion in a lambda expression (mainly in chords). If it is Python 3.8 or later, it will be refreshing. Let's compare with the function that finds the xth of the Fibonacci sequence.
〜Python3.7
print((lambda x: (lambda f, x: f(f, x))(lambda f, x: f(f, x-1)+f(f, x-2) if x > 2 else 1, x))(10))
# >> 55
Python3.8〜
print((self:=lambda x:self(x-1) + self(x-2) if x > 2 else 1)(10))
# >> 55
** Sugoku Sukiri **
Recommended Posts