0

What is the best method to convert a string like for example :

"[[1, 't'], ['gg', 2]]" which is a "quoted" list into:

[[1, 't'], ['gg', 2]]

To be more concrete, if I give as parameter to a python script a list it will be converted as a string automatically and I want to convert back this string into a list

So what i want is to "remove the quote" but i don't know what is the cleanest method to do it

Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
Xeyes
  • 583
  • 5
  • 25

1 Answers1

1

Use this :

from ast import literal_eval
s = "[[1, 't'], ['gg', 2]]"
l = literal_eval(s)

OUTPUT :

[[1, 't'], ['gg', 2]]
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56