Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python list inside string to list [duplicate]

I have a string: '[1, 2, 3]'
I want to convert it to: [1, 2, 3]

I know there was a single bif that I could use, but I couldn't find it or for the life of me recall what it was.

I know someone out there remembers, any help would be greatly appreciated.

like image 676
npengra317 Avatar asked Jul 22 '14 14:07

npengra317


1 Answers

To process a string as if were code:

>>> eval('[1, 2, 3]')
[1, 2, 3]
like image 193
mdurant Avatar answered Oct 12 '22 13:10

mdurant