1

I am doing some data cleaning from a file I read with pandas. I will illustrate the problem I have with a simple example.

I have the following string:

a = '["1","2","3"]' 

And I would like to turn it into a list. Therefore, I need to get rid of the outer quotes.

Final result should be:

a = ["1","2","3"]

So that I can access the list using indexes.

Thanks in advance!

1 Answers1

-2

You can make a workaround using list comprehension like :

>>> [x.strip('\"') for x in a.strip("[]").split(",")]
['1', '2', '3']
shaktimaan
  • 1,769
  • 13
  • 14