I'm trying to separate characters from any given strings and making subsring with it. For example,
str='abcd' => 'ab','bc','cd'
Here is my solution,
str='abcdef'
a=[]
for i in range(len(str)):
a.append(str[i:i+2])
a.remove(a[-1])
print(a)
This works but I would like to know better way to do it.
Thanks
[str[p:p+2] for p in range(len(str)-1)]stris a builtin function. Do not use it as a variable.