It's not too hard to see what's going wrong
>>> myarray = 'ABCDE'
>>> for i in range(len(myarray) + 1):
... a = i % len(myarray) ; b = i % len(myarray) + 2
... print a, b, myarray[a: b]
...
0 2 AB
1 3 BC
2 4 CD
3 5 DE
4 6 E
0 2 AB
There's no way you're going to get a slice like 'EA' without doing something heroic like
>>> myarray[::-4]
'EA'
The + 1
is obviously going to give you one more output than the number of items in myarray
Easy fix is something like this
>>> for i in range(len(myarray)):
... print (myarray*2)[i:i+2]
...
AB
BC
CD
DE
EA