I have a string extracted from a .csv which has this format:
str = "[point, contextual, point]"
What I wanna do is convert it to a list in the format:
str = ["point", "contextual", "point"]
How can I do it? I tried with json.loads(str) but I got the error:
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)
you could use:
my_str = "[point, contextual, point]"
my_str[1:-1].split(', ') # remove first and last characters ([]) and split on ", "
NB. don't use str as a variable name, this overwrites the str
builtin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With