Skip to content

Instantly share code, notes, and snippets.

@theelous3
Last active March 8, 2020 12:24
Show Gist options
  • Save theelous3/83e204bcb3d63f738ab53be424ab0dc4 to your computer and use it in GitHub Desktop.
Save theelous3/83e204bcb3d63f738ab53be424ab0dc4 to your computer and use it in GitHub Desktop.
def intersperse(xs, y, gap=1, pre=False):
for i, x in enumerate(xs):
if not pre:
yield x
if not i % gap:
yield y
if pre:
yield x
list(intersperse([1, 2, 3, 4, 5, 6], "X"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment