I have a string "ababa"
. I want to extract all the substring of length say, 2, and store it in a list like ['ab' , 'ba' , 'ab', 'ba' ]
.
Here is what i have already tried, (I beforehand know that size of string is N):
str = input()
for k in range (N- 2 +1)
sub[k] = str[k:k+2]
But this line of code gives error as the last line is illegal assignment. ( I am new to Python and have tried simply drawing a correlation with C++ )