Skip to content

Instantly share code, notes, and snippets.

@hrchu
Created November 25, 2019 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrchu/8acedf3c013a21fec0ada0fcb5c93a26 to your computer and use it in GitHub Desktop.
Save hrchu/8acedf3c013a21fec0ada0fcb5c93a26 to your computer and use it in GitHub Desktop.
Why map/filter is weaker than list comprehension or for loop iterating?
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'
@hrchu
Copy link
Author

hrchu commented Nov 25, 2019

Think lambda as general Python function. You need to do "*" in argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment