Last active
January 18, 2017 13:33
-
-
Save xiazhibin/7b958dd4f3b9ae25687b4e5f0f1faf50 to your computer and use it in GitHub Desktop.
This file contains 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
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