I would do it with a recursive method. Try this:
def split_str(seq, chunk, skip_tail=False):
lst = []
if chunk <= len(seq):
lst.extend([seq[:chunk]])
lst.extend(split_str(seq[chunk:], chunk, skip_tail))
elif not skip_tail and seq:
lst.extend([seq])
return lst
The answer is returned as a list. If we did:
print(split_str("some text", 3))
We would get a list looking like: ['som', 'e t', 'ext']
If you don't want to include spaces, add `.replace(" ", ""), like this:
print(split_str("some text".replace(" ", ""), 3))
This gives us: ['som', 'ete', 'xt']