0

I have the following list in Python:

['[0,0]', '[0,1]', '[1,0]', '[1,1]']

How can I remove the apostrophes around each list item?

Thanks.

Simplicity
  • 44,640
  • 91
  • 243
  • 375
  • 4
    Where did that list come from? The fix might be as simple as removing an errant `str()` call somewhere else. – Samwise Dec 01 '21 at 18:59

1 Answers1

1

Use eval carefully:

>>> [eval(l) for l in lst]
[[0, 0], [0, 1], [1, 0], [1, 1]]

Or json.loads:

import json

>>> [json.loads(l) for l in lst]
[[0, 0], [0, 1], [1, 0], [1, 1]]
not_speshal
  • 20,086
  • 2
  • 13
  • 28