I have a string a = '["Internet Software","IoT"]'. It is not a list. It is a string of length 27.
I want to convert this into a list containing elements : Internet Software and IoT.
How do I do so?
I have a string a = '["Internet Software","IoT"]'. It is not a list. It is a string of length 27.
I want to convert this into a list containing elements : Internet Software and IoT.
How do I do so?
use eval()
a = '["Internet Software","IoT"]'
lst = eval(a)
print type(lst)
# <type 'list'>
You have at least 2 options: eval and json.loads
import json
a = '["Internet Software","IoT"]'
print(eval(a)) # ['Internet Software', 'IoT']
print(json.loads(a)) # ['Internet Software', 'IoT']
I would recommend against eval, because it could execute malicious code.
json.loads on the other hand only works if your string is valid JSON (which is true for the string you posted).