-1

There's an string like this:

abcdefghijk

I want to slice it like this:

abc
bcd
cde
def
efg
fgh
ghi
hij
ijk

I googled but could not find any site or answers to reach this.

Update 1

My question is not similar to Split string every nth character?.

Saeed
  • 3,255
  • 4
  • 17
  • 36

1 Answers1

2
s = "abcdefghijk"
str_list = []
for i in range(len(s)-2):
    new_string = s[i] + s[i+1] + s[i+2]
    str_list.append(new_string)

for x in str_list:
    print(x)
Schnitte
  • 1,193
  • 4
  • 16