Created
April 26, 2020 13:05
-
-
Save petri/5feb706fa111fc853e5dd9ffff503f4d to your computer and use it in GitHub Desktop.
Get all ordered n-size splices of a sequence in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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