I’m splitting strings to generate keys for a dictionary but I’m having trouble with parentheses.
I’d like to take the string contemporary building(s) (2000 c.e. to present) and split it into three keys: contemporary, building(s), and (2000 c.e. to present)
Up to now, I’ve been using re.findall('\w+', key)
Any help is greatly appreciated.
You could use also
re.findall('[(][^)]*[)]|\S+', key), if you do not have parentheses within parentheses.