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
  • 47,404
  • 98
  • 256
  • 385
  • 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
  • 22,093
  • 2
  • 15
  • 30