Last active
August 29, 2015 14:16
-
-
Save alexandre/69a5c7865be995a66a7f to your computer and use it in GitHub Desktop.
a way to substitute a lambda in a map
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
| #!/usr/bin/python3 | |
| import itertools | |
| def gen_string(num, foo): | |
| return '{} - {}'.format(num, foo) | |
| def list_number_and_foo_sp(): #sp == situation problem | |
| foo = 'Something' | |
| return list(map(gen_string, range(10),foo)) | |
| def list_number_and_foo_with_lambda(): | |
| foo = 'Something' | |
| return list(map(lambda n: gen_string(n, foo), range(10))) | |
| def list_number_and_foo_with_repeat(): | |
| foo = 'Something' | |
| return list(map(gen_string, range(10), itertools.repeat(foo))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or a good reason to use a genexp: