I have a Python string (str
), which is "['Fish & Chips', 'Fast Food', 'Restaurants']"
.
How can I convert this string to a list?
See Question&Answers more detail:osI have a Python string (str
), which is "['Fish & Chips', 'Fast Food', 'Restaurants']"
.
How can I convert this string to a list?
See Question&Answers more detail:osEdit: See snakecharmerb's for a safer alternative to eval()
.
It seems like you're looking for eval()
, which takes a string and evaluates it as a Python expression:
s = "['Fish & Chips', 'Fast Food', 'Restaurants']"
eval(s)
# ['Fish & Chips', 'Fast Food', 'Restaurants']
type(eval(s))
# list