Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created March 9, 2021 16:11
Show Gist options
  • Save acdimalev/0e1efb126a300aeccf1df594a8d1d0b7 to your computer and use it in GitHub Desktop.
Save acdimalev/0e1efb126a300aeccf1df594a8d1d0b7 to your computer and use it in GitHub Desktop.
# Python 3 is an iterator-first language.
# `bind` and `join` are reaching wider adoption under the names `flatmap` and `flatten`.
def flatmap(f, xs):
return (y for x in xs for y in f(x))
def flatten(xs):
return (y for x in xs for y in x)
# These don't match the `zip(*args)` behavior of `map`, but I have never actually seen that used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment