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>

<p>You could also use regex to do this</p>

<pre><code>import re
s = "38.00,SALE ,15.20"
p = re.compile(r'\d+\.\d+')  # Compile a pattern to capture float values
floats = [float(i) for i in p.findall(s)]  # Convert strings to float
print floats
</code></pre>

<p>Output:</p>

<pre><code>[38.0, 15.2]
</code></pre>

python string