Created
September 20, 2022 20:45
-
-
Save ZhouYang1993/0dff5eac59bc09a0f3c332faf79ae3cf to your computer and use it in GitHub Desktop.
11 Stunning Python One-Liners That Amazed Me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib = lambda x: x if x <= 1 else fib(x - 1) + fib(x - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
I think the following inline function definition is as clean as the lambda is.
def fib ( x ) : return x if x <= 1 else fib ( x - 1 ) + fib ( x - 2 )
Plus it makes obvious that it's a function. Roughly reading a lamba as a neophyte leads to think the Fibonacci function result goes to the "fib" variable.
In this situation the lamba example might not be relevant.