Is there a way of splitting a word into 3 different parts in python?

char = "RV49CJ0AUTS172Y"

To get this output:

separated = "RV49C-J0AUT-S172Y"

I have tried:

split_strings = []
             n = 5
             for index in range(0, len(name), n):
                split_strings.append(name[index : index + n])

But that did not go as I wanted
This shows a good method but I want them on the same line with dashes between them

>Solution :

You can do it in one-line, using re

import re
string = "RV49CJ0AUTS172Y"

separated = "-".join(re.findall('.{%d}' % 5, string))




Leave a Reply