Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created September 20, 2022 20:45
Show Gist options
  • Save ZhouYang1993/0dff5eac59bc09a0f3c332faf79ae3cf to your computer and use it in GitHub Desktop.
Save ZhouYang1993/0dff5eac59bc09a0f3c332faf79ae3cf to your computer and use it in GitHub Desktop.
11 Stunning Python One-Liners That Amazed Me
fib = lambda x: x if x <= 1 else fib(x - 1) + fib(x - 2)
@PaliPalo
Copy link

PaliPalo commented Mar 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment