How to convert a `lambda` object to a` function` object in Python?
I've dealt with bugs regarding functions lambda
and their inability to be pickled
. I often use lambda
on-the-fly functions as disposable functions of use, and this dramatically reduces the productivity of my workflow when I have to individually recreate simple lambda functions in functional form for use with etching.
Is there a way to convert lambda
and all its arguments to an object function
in Python 3.6.1
?
lambda_func = lambda x: x.split(" ")
def func(x):
return x.split(" ")
input_string = "Darth Plagueis was a Dark Lord of the Sith"
# Function Version
func(input_string)
# ['Darth', 'Plagueis', 'was', 'a', 'Dark', 'Lord', 'of', 'the', 'Sith']
lambda_func(input_string)
# ['Darth', 'Plagueis', 'was', 'a', 'Dark', 'Lord', 'of', 'the', 'Sith']
def lambda2func(lambda_func):
#...
return func_version
source to share
No one has answered this question yet
See similar questions:
or similar: