Error: Unsupported Operand Types
<p>I'm trying to use recursion to return the dot product of two lists, and I'm trying to account for the situation in which I get two lists of different length: I return 0. However, when I try to check for that condition, I get the error: unsupported operand type(s) for &amp;: 'list' and 'list'. Why can't I use the '&amp;' operand for two lists in Python?</p>

<pre><code>def dot(L, K):
    if L+K == []:
        return 0
    elif L == [] &amp; K != []:
        return 0
    elif K == [] &amp; L != []:
        return 0 
    else:
        return L[-1] * K[-1] + dot(L[:-1], K[:-1])
</code></pre>

<pre><code>def dot(L, K):
    if len(L)!=len(K):  # return 0 before the first recursion
        return 0
    elif not L:  # test if L is [] - previous test implies K is [] so no need to retest
        return 0
    else:
        return L[-1] * K[-1] + dot(L[:-1], K[:-1])
</code></pre>

python math