How do you extract the floats from the elements in a python list?
<p>I am using BeautifulSoup4 to build a script that does financial calculations. I have successfully extracted data to a list, but only need the float numbers from the elements.</p>

<p>For Example:</p>

<pre><code>Volume = soup.find_all('td', {'class':'text-success'})

print (Volume)
</code></pre>

<p>This gives me the list output of:</p>

<pre><code>[&lt;td class="text-success"&gt;+1.3 LTC&lt;/td&gt;, &lt;td class="text- success"&gt;+5.49&lt;span class="muteds"&gt;340788&lt;/span&gt; LTC&lt;/td&gt;, &lt;td class="text-success"&gt;+1.3 LTC&lt;/td&gt;,]
</code></pre>

<p>I want it to become:</p>

<pre><code>[1.3, 5.49, 1.3]
</code></pre>

<p>How can I do this?</p>

<p>Thank-you so much for reading my post I greatly appreciate any help I can get.</p>

<p>You can do</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; re.findall("\d+\.\d+", yourString)
['1.3', '5.49', '1.3']
&gt;&gt;&gt; 
</code></pre>

<p>Then to convert to floats</p>

<pre><code>&gt;&gt;&gt; [float(x) for x in re.findall("\d+\.\d+", yourString)]
[1.3, 5.49, 1.3]
&gt;&gt;&gt; 
</code></pre>

python regex beautifulsoup