Skip to content

Instantly share code, notes, and snippets.

@petri
Created April 26, 2020 13:05
Show Gist options
  • Save petri/5feb706fa111fc853e5dd9ffff503f4d to your computer and use it in GitHub Desktop.
Save petri/5feb706fa111fc853e5dd9ffff503f4d to your computer and use it in GitHub Desktop.
Get all ordered n-size splices of a sequence in Python
def splice(sequence, size):
"return a list of all ordered splices of given size"
ss = len(sequence)
return [sequence[i:i+size] for i in range(0, ss-size+1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment