/python/series/series.py

1
2
3
4
5
6
7
8
9
10
def slices(digits, n):
    """Get all possible consecutive number series of length n
    in a string of digits"""

    if n > len(digits) or n == 0:
        raise ValueError

    digits = map(int, digits)
    return [digits[i:i+n]
            for i in range(0, len(digits)-n+1)]

Comments


You're not logged in right now. Please login via GitHub to comment