Skip to content

Instantly share code, notes, and snippets.

@igor-shevchenko
Created August 30, 2013 07:30
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 igor-shevchenko/6387173 to your computer and use it in GitHub Desktop.
Save igor-shevchenko/6387173 to your computer and use it in GitHub Desktop.
map and filter defined using reduce
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