Hello folks, i have a string <br><br>eg<br><br>"(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"<br><br>now i have to convert this string to<br><br>"(((A:1,B:1):2,C:3):1,((E:1,F:1):1,D:2):2)"<br>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.<br>
This is what my code looks like<br><br>import re<br><br>str = "(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"<br><br>p =re.compile('\d\):\d') # compiling an re object<br><br>list1 =[]<br><br>iterator = p.finditer(str)<br>
<br>for match in iterator:<br><br> x = match.group()<br><br> l = x.split('):')<br> <br> value = int(l[1])-int(l[0])<br><br> z= repr(value)<br><br> rm = l[1]<br><br> x= x.rstrip(rm)<br>
<br> y = x + repr(value) <br><br> print y<br><br>I am able to get the desired output further, any help is appreciated<br><br>Thanks<br><br>Aditya<br>