오은아은아 오은아은아 - 1 year ago 97
Python Question

I want adding string @ in every second comma

a = 'a,b,c,d,e,f,g,e'


I want to change
'a,b,c,d,e,f,g,e'
to
'a,b@c,d@e,f@g,e'
.

Is it possible?

Answer Source

For the regex lovers:

import re

input = 'a,b,c,d,e,f,g,e'

output = re.sub(r',([^,]*),', r',\1@', input)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download