Convert a string representation of list to list.
Answer / Amit Kumar Gangele
In Python, you can convert a string representation of a list using the built-in `ast.parse` and `ast.literal_eval` functions. Here is an example: nn``pythonnimport astnnlist_str = '[1, 2, 3, 4]'nlist_obj = ast.literal_eval(ast.parse(list_str).body)[0]nnprint(list_obj) # Output: [1, 2, 3, 4]
| Is This Answer Correct ? | 0 Yes | 0 No |
Why anaconda is used for python?
Can you sort a string in python?
Is python better than matlab?
How is unit test done in python?
What is tuple in python?
In Python what is slicing?
What is a class method?
How are arguments passed by value or by reference in Python?
Explain how to copy an object in Python.
Where is python used?
Is python a good first language?
What is sphinx in python?