parse list from string 1

parse list from string

import ast

x = '["A","B","C","D"]'
x = ast.literal_eval(x)

# Returns: ['A', 'B', 'C', ' D']

Here is what the above code is Doing:
1. The ast.literal_eval() function takes a string as input and returns the data structure it represents.
2. The string is a list of strings, so the function returns a list of strings.

Similar Posts