Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.