Python: Extract multiple float numbers from string
<p>Forgive me, I'm new to Python.</p>

<p>Given a string that starts with a float of indeterminate length and ends with the same, how can I extract both of them into an array, or if there is just one float, just the one.</p>

<p>Example: </p>

<pre><code>"38.00,SALE ,15.20"
"69.99"
</code></pre>

<p>I'd like to return:</p>

<pre><code>[38.00, 15.20]
[69.99]
</code></pre>

<pre><code>import re    
map(float, filter(lambda x: re.match("\s*\d+.?\d+\s*", x) , input.split(","))
</code></pre>

<p>Input :     <code>input = '38.00,SALE ,15.20'</code> Output: <code>[38.0, 15.2]</code></p>

<p>Input : <code>input = '38.00,SALE ,15.20, 15, 34.'</code> Output:  <code>[38.0, 15.2, 15.0, 34.0]</code></p>

<p>Explanation: </p>

<ol>
<li>Idea is to split the string : <code>list_to_filter = input.split(",")</code> splits on <code>,</code> </li>
<li>Then using regex filter strings which are real numbers: <code>filtered_list = filter(&lt;lambda&gt;, list_to_filter)</code> , here item is included in output of filter if lamda expression is true. So when <code>re.match("\s*\d+.?\d+\s*", x)</code> matches for string <code>x</code> filter keeps it. </li>
<li>And finally convert into float. <code>map(float, filtered_list)</code>. What it does is apply <code>float()</code> function to each element of the list</li>
</ol>

python string