Converting a List Into Float Variables
<p>I'm wanting to take an input as a list but use each variable as a float. Is there a simpler way to make this conversion other than explicitly like I do below, as a list is defined with strings, and I want to, for example, add rather than concatenate:</p>

<pre><code>edges = input("Enter three edges: ").split(", ")  
print("The perimeter is", (float(edges[0]) + float(edges[1]) + float(edges[2])))
</code></pre>

<p>You could use <code>map</code> to transform to <code>float</code>s and then <code>sum</code> to sum them up:</p>

<pre><code>print("The perimeter is", sum(map(float, edges)))
</code></pre>

<p><code>map</code> takes a callable (<code>float</code> here), and applies it to every element of an iterable (<code>edges</code> here). This creates a <code>map</code> iterator (something that can be iterated through) that is then supplied to <code>sum</code> which sums it up.</p>

<p>Then you print it.</p>

<p>You could of course create an ugly little expression that combines them all together because both <code>input</code> and <code>split</code> return their results:</p>

<pre><code>print("Sum is ", sum(map(float, input('Enter three edges ' ).split(","))))
</code></pre>

<p>but don't, <em>it's ugly</em>.</p>

python list python-3.x floating-point