python - Grab elements inside parentheses -
how can grab elements inside parentheses , put them in file?
me (i) (you) him (he) (she)
thanks in advance, adia
import re txt = 'me (i) (you) him (he) (she)' words = re.findall('\((.+?)\)', txt) # words returns: ['i', 'you', 'he', 'she'] open('filename.txt', 'w') out: out.write('\n'.join(words)) # file 'filename.txt' contains now:
Comments
Post a Comment