-3

I have a string, something like:

a = "[1, 2, 3]"

If there an easy way to convert it in to a list, without using .split(), join() etc.

Thanks for any replies.

Oleg Klimenko
  • 138
  • 1
  • 5
  • 20

1 Answers1

1

use ast.literal_eval() it's safer than using eval

from ast import literal_eval

a = literal_eval("[1, 2, 3]")

print(a)
danidee
  • 9,298
  • 2
  • 35
  • 55