I have a string field : [42, 42, 42]. I want to convert this field in list format.
For now i have the following function :
def stringToList(string):
# input format : "[42, 42, 42]" , note the spaces after the commas
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 to have the same result.
Thank you