Created
August 30, 2013 07:30
-
-
Save igor-shevchenko/6387173 to your computer and use it in GitHub Desktop.
map and filter defined using reduce
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
def map_(function, iterable): | |
return reduce(lambda lst, cur: lst + [function(cur)], iterable, []) | |
def filter_(function, iterable): | |
return reduce(lambda lst, cur: ((lst + cur) if type(iterable) is str else (lst + (cur,) if type(iterable) is tuple else lst + [cur])) if (function if function is not None else bool)(cur) else lst, iterable, '' if type(iterable) is str else tuple() if type(iterable) is tuple else []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment