I have a string that contains numbers. The string needs to separate the numbers by chunks of 3. If necessary, the last chunk, or the last two chunks can contain 2 numbers (but never 1).
Examples:
"123456789" -> "123-456-789"
"1234567891" -> "123-456-78-91"
"12345678912" -> "123-456-789-12"
Working with chunks of three is straight forward:
'-'.join(S[i:i+3] for i in range(0, len(S),3))
How can I extend this?