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
  • 32,724
  • 9
  • 46
  • 70
amro_ghoneim
  • 455
  • 1
  • 4
  • 10

3 Answers3

2

Use eval():

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

arr = eval(arr)
ihavenoidea
  • 609
  • 1
  • 10
  • 21
2

Keeping away from dangers of eval you can use literal_eval

ast.literal_eval("[[[234],[432],[523]]]") #[[[234], [432], [523]]]
mad_
  • 7,844
  • 2
  • 22
  • 37
1

Try eval() function of python.

>>> arr=eval("[[[234],[432],[523]]]")
>>> arr
[[[234], [432], [523]]]
Hamza Khurshid
  • 697
  • 9
  • 16