Skip to content

Instantly share code, notes, and snippets.

@lidavidm
Created May 23, 2015 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidavidm/997bf6e61c3bc520655b to your computer and use it in GitHub Desktop.
Save lidavidm/997bf6e61c3bc520655b to your computer and use it in GitHub Desktop.
>>> 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