Given:
s = 'foo, bar, baz, qudz'
I would like to split this string given 2 criteria:
- a character count n (in this case, I'll use n = 10)
- the delimiter: ", " (before the nth character)
Desired Result:
['foo, bar', 'baz, qudz']
I know I can split it by delimiter easily enough:
s.split(', ')
['foo', 'bar', 'baz', 'qudz']
I also know that I can split it into even chunks of n like this:
[s[i:i+n] for i in range(0, len(s), n)]
I've also seen where I can split by the nth delimiter here.