Python - TypeError: float() argument must be a string or a number, not 'list
<p>Python newbie here. I am trying to operate on lists which contain floating point numbers. <code>avg</code> is a list parameter that is returned from a different method. However, when I tried doing the following, it throws me an error that float() should have a string or a number and not a list. <code>avg1</code> should contain a copy of the lists with float-type numbers instead of lists right? I tried a few edits I read on other posts with similar titles, but couldn't solve this.
Just starting out so kindly tell me where I am going wrong. </p>

<pre><code>def movingavg(EMA,avg):     
    EMA=[]
    avg1 = [float(i) for i in avg]
    EMA[:3] = avg1[:3]
    for i,j in zip(EMA[2:],avg1[3:]):
        a =float(i)*0.67 + float(j)*0.33
        EMA.append(a)
    return EMA
</code></pre>

<p>The error that I get is as follows :</p>

<pre><code>avg1 = [float(i) for i in avg]
TypeError: float() argument must be a string or a number, not 'list'
</code></pre>

<p>Using Python 3.4</p>

<p>Instead of <code>avg1 = [float(i) for i in avg]</code> use below code.</p>

<pre><code>avg1 = []
for i in avg:
    for j in i:
        avg1.append(float(j))
</code></pre>

<p>or can use below list comprehension.</p>

<pre><code>avg1 = [float(i)  for val in avg for i in val]
</code></pre>

python python-3.x