Skip to content

Instantly share code, notes, and snippets.

@xordoquy
Created February 11, 2015 17:12
Show Gist options
  • Save xordoquy/2a209c899def3a46666c to your computer and use it in GitHub Desktop.
Save xordoquy/2a209c899def3a46666c to your computer and use it in GitHub Desktop.
array = []
for i in range(5):
def demo():
return i
array.append(demo)
[item() for item in array]
@bors-ltd
Copy link

array = []
for i in range(5):
    def demo(argument_is_only_local_variable=i):
        return argument_is_only_local_variable
    array.append(demo)

[item() for item in array] 

But it feels like I'm influenced by making your snippet work, not what could be your actual use case.

@Exirel
Copy link

Exirel commented Feb 11, 2015

>>> 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