I have a Python string (str), which is "['Fish & Chips', 'Fast Food', 'Restaurants']".
str
"['Fish & Chips', 'Fast Food', 'Restaurants']"
How can I convert this string to a list?
Edit: See snakecharmerb's for a safer alternative to eval().
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
1.4m articles
1.4m replys
5 comments
57.0k users