Created
November 25, 2019 06:08
-
-
Save hrchu/8acedf3c013a21fec0ada0fcb5c93a26 to your computer and use it in GitHub Desktop.
Why map/filter is weaker than list comprehension or for loop iterating?
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
alist = [[1,1],[1,1]] | |
assert([1, 1] == [x for x, y in alist]) # OK | |
for x, y in alist: # OK | |
assert x == 1 | |
assert([1, 1] == list(map(lambda x, y: x, alist))) # TypeError: <lambda>() missing 1 required positional argument: 'y' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Think lambda as general Python function. You need to do "*" in argument.