Created
February 11, 2015 17:12
-
-
Save xordoquy/2a209c899def3a46666c 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
array = [] | |
for i in range(5): | |
def demo(): | |
return i | |
array.append(demo) | |
[item() for item in array] |
>>> demos = (lambda: i for i in range(5))
>>> [item() for item in demos]
[0, 1, 2, 3, 4]
Thanks the generator expression.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But it feels like I'm influenced by making your snippet work, not what could be your actual use case.