r/Python • u/dankey26 • Dec 19 '22
Intermediate Showcase multi line lambdas, as god intended

codec abuse, part 2. https://github.com/dankeyy/superlambda.py
gl hf hope you like it
54
Upvotes
r/Python • u/dankey26 • Dec 19 '22

codec abuse, part 2. https://github.com/dankeyy/superlambda.py
gl hf hope you like it
2
u/igeorgehall45 Dec 20 '22
You could write:
or, abusing walrus for a dodgy
functools.reduceor, just using
import(math);f=math.factorial90
u/RevolutionFuzzy2059 Dec 19 '22
Mfs will do anything not to define a function
1
u/JoshuaTheProgrammer Dec 20 '22
Unrelated but what font are you using for the λ? It looks so good!
1
u/iceytomatoes Dec 31 '22
u/dankey26 i wonder if this might be up your alley
i mostly do scientific programming in python and have no idea how to implement this, but your playing with these lambdas made me think a bit
is it possible to make a package that imports to make 'lambda' interchangeable with 'given' to make it more readable
and perhaps to fix the
2
u/gut_busta Dec 20 '22
Can someone explain what is going on here to a non-programmer. I believe a may be a lostredditor but I want to be in on this joke.
2
u/the_scign Dec 20 '22
Now all we need is a decorator that turns a function into a lambda /s
1
u/iceytomatoes Dec 20 '22
love me some bastardized python
1
u/OkProfessional8364 Dec 20 '22
So you replaced 'def f(n):' but why
0
u/igeorgehall45 Dec 20 '22
just for fun,
fib = lambda x,a=0,b=1: [(b:=a+b,a=:b-a) for _ in range(x)][-1][-1]and yes, i know this is both broken for fib(x) where x < 1, and inefficent, and unreadable, but that's not the point, the point is that walrus gives too much power to list comprehensions by being expressions.