-1

I have this string

'['foo', 'faa', 'fee']'

I want to transform it as a list of strings like:

['foo', 'faa', 'fee']

how could I do that?

Omar
  • 1,029
  • 2
  • 13
  • 33
  • I would start by fixing whatever is producing that string. Python string representations are meant for debugging and display purposes, not for sharing data between processes. – chepner Oct 10 '21 at 15:40

1 Answers1

1

Use ast package

from ast import literal_eval

s = "['foo', 'faa', 'fee']"
l = literal_eval(s)
print(type(l))

Output

<class 'list'>
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55