can you help me to optimize this code
<p>can you help me to optimize this code </p>

<pre><code>def calc_potential(time, firstsale, lastsale, sold, supplied):
    retval = []
    for t, f, l, c, s in zip(time, firstsale, lastsale, sold, supplied):
        try:
            if s &gt; c:
                retval.append(c)
            else:
                s = (l - t).total_seconds() / 3600.
                d = ((t - f).total_seconds() / 3600.) / c
                retval.append(s / d + c)
        except:
            retval.append(None)

    return retval
</code></pre>

<p>Keeping in mind some of the comments i.e. this is not for optimizing but rather fixing broken code, I can point you in the right direction:</p>

<p>To replace this section of code: </p>

<pre><code>if s &gt; c:
  retval.append(c)
</code></pre>

<p>For something more efficient, try list comprehension:</p>

<pre><code>retval= [c for c, s in zip(sold, supplied) if s&gt;c]
</code></pre>

<p>If you do something similar for the code in the else statement as well, and combine both lists. You will have what you want in one possible way. </p>

python