Surprising behaviour of enumerate function
<p>I wrote some Python code using the enumerate function. </p>

<pre><code>A = [2,3,5,7]

for i, x in enumerate(A):
    # calculate product with each element to the right
    for j, y in enumerate(A, start=i+1):
        print(x*y)
</code></pre>

<p>I expected it to calculate 6 products: 2*3, 2*5, 2*7, 3*5, 3*7, 5*7</p>

<p>Instead, it calculated all possible 16 products. What's going on?</p>

<p>The <code>start</code> parameter of <code>enumerate</code> solely influences the first value of the yielded tuple (i.e. <code>i</code> and <code>j</code>), it does not influence at which index the enumeration starts. As <a href="https://docs.python.org/3/library/functions.html#enumerate">the manual</a> puts it, <code>enumerate</code> is equivalent to this:</p>

<pre><code>def enumerate(sequence, start=0):
    n = start
    for elem in sequence:
        yield n, elem
        n += 1
</code></pre>

<p>What you want is this:</p>

<pre><code>for i, x in enumerate(A):
    for y in A[i + 1:]:
        print(x * y)
</code></pre>

python