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>

<p>I would probably do something like this:</p>

<pre><code>def dot(L, K):
    if L + K == [] or len(L) != len(K): # this only needs to be checked once
        return 0
    return dot_recurse(L, K)

 def dot_recurse(L, K):
     if len(L) &gt; 0:
         return L[-1] * K[-1] + dot_recurse(L[:-1], K[:-1])
     else:
         return 0;
</code></pre>

python math