I have a string field : "[Paris, Marseille, Pays-Bas]". I want to convert this string to a list of strings.
For now I have the following function :
def stringToList(string):
string = string[1:len(string)-1]
try:
if len(string) != 0:
tempList = string.split(", ")
newList = list(map(lambda x: str(x), tempList))
else:
newList = []
except:
newList = [-9999]
return(newList)
I want to know if there is a simpler or a shorter method with the same results.
I could use ast.literal_eval() if my input data were of type int. But in my case, it does not work.
Thank you