Strip string values in a dictionary and convert it to a float. Values contain numbers separated by space
<p>I have a dictionary setup with the following data:</p>

<p><img src="http://i.stack.imgur.com/onSzu.jpg" alt="image of dictionary with values"></p>

<p>where its values are a list of <strong>strings</strong>:</p>

<pre><code>['2 1 0\n', '3 0 1\n', '4 0 3\n' .... ]   
['-3.85995e-17  1.26224e+00  2.63053e-01\n']
</code></pre>

<p>Is there a way I can convert the values into a list of <strong>floats</strong> without having to use too many loops?</p>

<p>You would probably have to find a library that handles such data to do it for you, I'm not aware of any native python method to convert a string into a list of floats.
If you're looking to save space, it'd probably just be easiest to write your own function that takes one of your values and returns a list of floats.</p>

<p>For example:</p>

<pre><code>def string_to_float_list(string):
    split = string.strip().split(" ")
    floats = []    
    for s in split:
        if len(s) == 0:
            continue
        floats.append(float(s.strip()))
    return floats
</code></pre>

<p>Takes input:</p>

<pre><code>string = '-3.85995e-17  1.26224e+00  2.63053e-01\n'
</code></pre>

<p>Gives output:</p>

<pre><code>[-3.85995e-17, 1.26224, 0.263053]
</code></pre>

python string dictionary