-2
'[1, 2]' 

It is a string. How to I make it List [1,2]

So convertion from '[1, 2]' to [1,2]

Iqbal Hussain
  • 1,077
  • 1
  • 4
  • 12

1 Answers1

2

You have a couple of options

eval

eval('[1, 2]')
# [1, 2]

ast.literal_eval

import ast
ast.literal_eval('[1, 2]')
# [1, 2]

string parsing

list(map(int, '[1, 2]'.strip('[]').split(', ')))
# [1, 2]
Steven Summers
  • 5,079
  • 2
  • 20
  • 31