Hi I have the following string:
s = '{'abc', 'def'}'
I want to create a list
L = ['abc', 'def']
How is best to achieve this?
I can do the standard replace etc and create a list but keeping in mind the length + # of elements of s will change.
Hi I have the following string:
s = '{'abc', 'def'}'
I want to create a list
L = ['abc', 'def']
How is best to achieve this?
I can do the standard replace etc and create a list but keeping in mind the length + # of elements of s will change.
If you have situation such as this one:
s = "{'abc', 'def'}"
Use literal_eval :
from ast import literal_eval
list(literal_eval(s))
['abc', 'def']