Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active January 18, 2017 13:33
Show Gist options
  • Save xiazhibin/7b958dd4f3b9ae25687b4e5f0f1faf50 to your computer and use it in GitHub Desktop.
Save xiazhibin/7b958dd4f3b9ae25687b4e5f0f1faf50 to your computer and use it in GitHub Desktop.
def multipliers():
return [lambda x : i * x for i in range(4)]
print [m(2) for m in multipliers()]
def multipliers():
for i in range(4): yield lambda x : i * x
def multipliers():
return [lambda x, i=i : i * x for i in range(4)]
from functools import partial
from operator import mul
def multipliers():
return [partial(mul, i) for i in range(4)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment