I am trying to split my nested list of strings into nested lists of floats. My nested list is below:
nested = [['0.3, 0.4, 0.2', '0.5, 0.1, 0.3'], ['0.7, 0.4, 0.2'], ['0.4, 0.1, 0.3']]
My desired output would be a nested list where these values remain in their sublist and are converted to floats as seen below:
nested = [[0.3, 0.4, 0.2, 0.5, 0.1, 0.3], [0.7, 0.4, 0.2], [0.4, 0.1, 0.3]]
The difficulty has come when trying to handle sublists with multiple strings (I.e. the first element). I have found some examples such as here How do I split strings within nested lists in Python?, but this code only handles sublists with one string element and I'm unsure how to apply this to sublists with multiple strings.
I am trying to avoid hardcoding anything as this is part of a script for a larger dataset and the sublist length may vary.
If anyone has any ideas, I'd appreciate some help.