Hello folks, i have a string

eg

"(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"

now i have to convert this string to

"(((A:1,B:1):2,C:3):1,((E:1,F:1):1,D:2):2)"
So i used the logic eg. taking the substring "1):3" and converting it to
"1):2"(3-1=2) so on for all the similar substrings.But i am not able to
replace them back into the original string.
This is what my code looks like

import re

str = "(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"

p =re.compile('\d\):\d') # compiling an re object

list1 =[]

iterator = p.finditer(str)

for match in iterator:

       x = match.group()

       l = x.split('):')

       value = int(l[1])-int(l[0])

       z= repr(value)

       rm = l[1]

       x= x.rstrip(rm)

       y = x + repr(value)

      print y

I am able to get the desired output further, any help is appreciated

Thanks

Aditya
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to