python 3.x - How to turn a string lists into a lists? -
there other threads turning strings inside lists different data types. want turn string in form of lists lists. this: "[5,1,4,1]" = [5,1,4,1]
i need because writing program requires user input lists
example of problem:
>>> x = input() [3,4,1,5] >>> x '[3,4,1,5]' >>> type(x) <class 'str'>
if mean evaluate python objects this:
x = eval('[3,4,1,5]'); print (x); print(type(x) list) [3, 4, 1, 5] true
use caution can execute user input. better use parser native lists. use json input , parse it.
Comments
Post a Comment