Python: Dividing a string into substrings -


i have bunch of mathematical expressions stored strings. here's short one:

stringy = "((2+2)-(3+5)-6)" 

i want break string list contains information in each "sub-parenthetical phrase" (i'm sure there's better way phrase that.) yield be:

['2+2','3+5'] 

i have couple of ideas how this, keep running "okay, what" issue.

for example:

for x in stringy:     substring = stringy[stringy.find('('+1 : stringy.find(')')+1]     stringlist.append(substring) 

works peachy return 2+2, that's far goes, , blanking on how move through remainder...

one way using regex:

import re stringy = "((2+2)-(3+5)-6)" exp in re.findall("\(([\s\d+*/-]+)\)", stringy):     print exp  

output

2+2 3+5 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -