1

I have a string that looks like this:

arr = "[[[234],[432], ..., [523]]]"

I want to extract the array in this string so that it becomes:

arr = [[[234], [432], ..., [523]]]

how do I go about doing this?

CristiFati
  • 38,250
  • 9
  • 50
  • 87
amro_ghoneim
  • 495
  • 1
  • 4
  • 14

3 Answers3

2

Use eval():

arr = "[[[234],[432], [523]]]"

arr = eval(arr)
ihavenoidea
  • 629
  • 1
  • 7
  • 26
2

Keeping away from dangers of eval you can use literal_eval

ast.literal_eval("[[[234],[432],[523]]]") #[[[234], [432], [523]]]
mad_
  • 8,121
  • 2
  • 25
  • 40
1

Try eval() function of python.

>>> arr=eval("[[[234],[432],[523]]]")
>>> arr
[[[234], [432], [523]]]
Hamza Khurshid
  • 765
  • 7
  • 18