The split method for strings only takes a parameter for the delimiter, but how do I easily split by every (or every other, etc) letter? This method works to split by every letter, but seems clumsy for a simple task.
a=' '.join(string.ascii_lowercase).split()
I suppose a function could do this:
def split_index(string,index=1):
split=[]
while string:
try:
sect = string[:index]
string = string[index:]
split.append(sect)
except IndexError:
split.append(string)
return split
print(split_index('testing')) # ['t', 'e', 's', 't', 'i', 'n', 'g']
print(split_index('testing',2)) # ['te', 'st', 'in', 'g']
I am surprised if no one has wished for this before, or if there is not a simpler built in method. But I have been wrong before. If such a thing is not worth much, or I have missed a detail, the question can be deleted/removed.