I am trying to Parse the following string:
EDITED to account for spaces…
['THE LOCATION', 'THE NAME', 'THE JOB', 'THE AREA')]
Right now I use regular expressions and split the data with the comma into a list
InfoL = re.split(“,”, Info)
However my output is
'THE LOCATION'
'THE NAME'
'THE JOB'
'THE AREA')]
Looking to have the output as follows
THE LOCATION
THE NAME
THE JOB
THE AREA
Thoughts?
One possibility is to use
strip()to remove the unwanted characters:Like your original solution, this will break if any of strings are allowed to contain commas.
P.S. If that closing parenthesis in your example is a typo, you might be able to use
ast.literal_eval():