Skip to content
Advertisement

Is there a built-in way for converting a list to a function?

Suppose I have a Python list lst. I want to convert this to a function or callable, which may be done by:

JavaScript

or (less preferably):

JavaScript

However, as this seems to be a very natural operation, I wondered whether there exists a built-in (perhaps more efficient) way to achieve this.

(To be a little bit more precise: Is there a Python built-in function convert such that I could write lst_as_function = convert(lst)?)

Does anybody know?

Advertisement

Answer

There actually is (if I understand your question correctly):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement