Hmm, I’d be tempted to try this using regex and a loop.
I haven’t given this a ton of thought, and my knowledge of pythonesque regex is limited, but I toyed with some strings and a naive regex pattern on regex101.com
Sorry for image, I’m on mobile.
You can see a rough pattern here and that it works for abacaba strings, but this doesn’t account for the ‘exactly one’ requirement - that’s where a loop might come in (or just a simple count of the number of abacaba substrings might work, now that I think about it).
It’s been a while since I regexed with Python so I can’t confirm the syntax is the same as JS.
It’s probably not the best way to do this, but it’s the first idea that occurred to me.
Edit: just noticed my regex pattern in the image has a rogue
. in there you should ignore!