Last active
July 9, 2021 03:27
-
-
Save js51/2f108eba6c7527c26b729fd106a0cc27 to your computer and use it in GitHub Desktop.
Python closure example
This file contains hidden or 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 function_factory(things): | |
| funcs = [] | |
| for thing in things: | |
| def do_something(x, _thing=thing): | |
| return do_some_stuff(x, _thing) | |
| funcs.append(do_something) | |
| return funcs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment