Skip to content

Instantly share code, notes, and snippets.

@RHDZMOTA
Created December 14, 2021 05:07
Show Gist options
  • Save RHDZMOTA/eee77861763e500888190c5d7677d03e to your computer and use it in GitHub Desktop.
Save RHDZMOTA/eee77861763e500888190c5d7677d03e to your computer and use it in GitHub Desktop.
An updated version of George Lydakis python script on lambda functions: http://ldkge.com/complex-python-lambdas.html
_ = (
lambda: [
_
# Imports
for sys in [__import__('sys')]
for math in [__import__('math')]
# Helper functions
for sub in [lambda *vals: None]
for fun in [lambda *vals: vals[-1]]
# Echo (just a print wrapper)
for echo in [lambda *vals: sub(
print(*vals, sep="\n"))]
# Class definition
for Cylinder in [type('Cylinder', (object,), dict(
__init__ = lambda self, radius, height: sub(
setattr(self, 'radius', radius),
setattr(self, 'height', height)
),
volume = property(
lambda self: fun(*[
self.height * top_area
for top_area in [math.pi * self.radius ** 2]
])
)
))]
# Main function definition
for main in [
lambda: sub(
[_ for factor in [1, 2, 3] if sub(
[
_
for my_radius, my_height in [[10 * factor, 20 * factor]]
for my_cylinder in [Cylinder(my_radius, my_height)]
if echo(
"A cylinder with a radius of %.1fcm and a height "
"of %.1fcm has a volume of %.1fcm³."
% (my_radius, my_height, my_cylinder.volume)
)
],
)]
)
]
# Main function execution
if main()
]
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment