I have a list in python which is produced from a number of functions. It is produced like this:
['01', '1.0', '[0.2]']
I would like to strip all of the unnecessary characters after it is produced.
Ideal output:
['01', '1.0', '0.2']
I basically need to remove the [ and ] from the final string in the list.
Update:
list_test = ['01', '1.0', '[0.2]']
[i.strip('[]') if type(i) == str else str(i) for i in list_test]
print(list_test)
This doesn't work as both with and without produce the same result:
['01', '1.0', '[0.2]']
The required result is:
['01', '1.0', '0.2']
Provided solution:
l = ['01', '1.0', '[0.2]']
[i.strip('[0.2]') if type(i) == str else str(i) for i in l]
print(l)
output:
['01', '1.0', '0.2']
Process finished with exit code 0