Skip to content

Instantly share code, notes, and snippets.

@brthornbury
Created September 10, 2016 05:05
Show Gist options
  • Save brthornbury/34e4cfd2f9ea560746d3f5b484f32ccd to your computer and use it in GitHub Desktop.
Save brthornbury/34e4cfd2f9ea560746d3f5b484f32ccd to your computer and use it in GitHub Desktop.
Lambdas that Rock, Rewriting Python on the Fly

For a long time, I've had a distaste for the syntax of lambda expressions in python.

add1 = lambda value: value + 1
print add1(1)
>>> 2

Compared to syntaxes for the same effect in other languages (like c#), it seems clunky.

var add1 = (x) => x+1;
Console.WriteLine(add1(1));
>>> 2

I thought there must be a way to achieve cleaner syntax in python, and started looking for a solution.

My first thoughts went back to c++ days and operator overloads. Research into these in python yielded some interesting results.

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