TypeError: Calculating dot product in python
<p>I need to write a Python function that returns the sum of the pairwise products of listA and listB (the two lists will always have the same length and are two lists of integer numbers).</p>

<p>For example, if listA = [1, 2, 3] and listB = [4, 5, 6], the dot product is 1*4 + 2*5 + 3*6, so the function should return: 32</p>

<p>This is how I wrote the code so far, but it produces an error.</p>

<pre><code>def dotProduct(listA, listB):
    '''
    listA: a list of numbers
    listB: a list of numbers of the same length as listA
    '''
    sum( [listA[i][0]*listB[i] for i in range(len(listB))] )
</code></pre>

<p>It prints: <code>TypeError: 'int' object is not subscriptable</code></p>

<p>How can I change this code so that the elements in the list can be multiplied element-wise?</p>

<p>Remove the offending portion (attempting to subscript an int):</p>

<pre><code>sum([listA[i]*listB[i] for i in range(len(listB))])
</code></pre>

python function python-3.x typeerror dot-product