Python split string in moving window

后端 未结 4 2226
天涯浪人
天涯浪人 2020-12-03 11:39

I have a string with digits like so - digit = \"7316717\"

Now I want to split the string in such a way that the output is a moving window of 3 digits at

4条回答
  •  旧巷少年郎
    2020-12-03 12:28

    >>> s = "7316717"
    >>> [s[i:i+3] for i in range(len(s)-2)]
    ['731', '316', '167', '671', '717']
    

提交回复
热议问题