Iterating through two lists, operating and creating a third list in Python
<p>I am a completely Python beginner and am really struggling with iterations on Lists! 
There's this problem I have been trying to solve using python using Lists:</p>

<p>I have a "<strong>TotalList</strong>" for the total costs on each hour for a product:</p>

<p>Hr  totalcost<br>
1   100<br>
2   50<br>
...<br>
24  150</p>

<p>And I have <strong>minList</strong> which has the % of the total cost in that hour for that minute </p>

<p>Hr  Min    (%) Cost<br>
1    1     1.0<br>
1    2     5.0<br>
...<br>
2    1     2.0<br>
2    2     4.0<br>
...
24   1     2.3     </p>

<p>I want to evaluate <strong>for each hour</strong> the total cost in every minute and put it in a third list. That list <strong>minuteCost</strong> would look like this:</p>

<p>Hr  Min    Cost<br>
1    1     totalList [0][2] *  minList [0][2]<br>
1    2     totalList [1][2] *  minList [1][2]<br>
...<br>
2    1     xxx<br>
2    2     xxx<br>
...<br>
24   1     xxx</p>

<p>I am sure there's an easy way to do this! Any suggestion would be much appreciated! I would also appreciate solutions based on numpy.</p>

<p>Easiest for a beginner to understand IMO:</p>

<pre><code>minuteCost = []
x = 0
for i in minList:
    tempList = [i[0], i[1], totalList[x][1]*i[2]]
    minuteCost.append(tempList)
    x += 1
</code></pre>

<p>This assumes that TotalList and minList are the same length.</p>

python list numpy comparison