Published: 03 November 2020, 18:00
As we said, comprehensions compiled into functions. That means, we can take a types.CodeType object for a comprehension, wrap it into types.FunctionType, and get a function.
[x*2 for x in _]
code = make.__code__.co_consts
func = types.FunctionType(code, globals())
# call the function!
# [0, 2, 4, 6, 8]