Created
May 23, 2015 05:08
-
-
Save lidavidm/997bf6e61c3bc520655b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import functools | |
>>> def thingy(a, b): | |
... return "{} {}".format(a, b) | |
... | |
>>> data = [0, 1, 2, 3, 4] | |
>>> a, *b = data | |
>>> a | |
0 | |
>>> b | |
[1, 2, 3, 4] | |
>>> [functools.update_wrapper(functools.partial(thingy, b=item), thingy) for item in b] | |
[functools.partial(<function thingy at 0x7f7ac0412bf8>, b=1), functools.partial(<function thingy at 0x7f7ac0412bf8>, b=2), functools.partial(<function thingy at 0x7f7ac0412bf8>, b=3), functools.partial(<function thingy at 0x7f7ac0412bf8>, b=4)] | |
>>> [func.__name__ for func in [functools.update_wrapper(functools.partial(thingy, b=item), thingy) for item in b]] | |
['thingy', 'thingy', 'thingy', 'thingy'] | |
>>> [func(i) for i,func in enumerate([functools.update_wrapper(functools.partial(thingy, b=item), thingy) for item in b])] | |
['0 1', '1 2', '2 3', '3 4'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment