On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano <st...@pearwood.info> wrote: > I have a function, which I put into an expression like this: > > def func(a, b=None): > global spam > import math > spam = [a, b]*3 > print spam > del spam > > > value = [1, "hello", int, func] > del func > > How would I use lambdak to write that as an expression > > value = [1, "hello", int, ??????? ] > > without the intermediate def?
# Untested, but seems like this should work. value = [1, "hello", int, given_(lambda a, b=None: import_("math", lambda math: import_("operator", lambda operator: do_(lambda: operator.setitem(globals(), 'spam', [a, b]*3), lambda: print_(globals()['spam'], lambda: do_(lambda: operator.delitem(globals(), 'spam')))))))] To the OP: I note that although import_ is used in the examples, it's not found in the list of functions in the README. -- https://mail.python.org/mailman/listinfo/python-list