Change next list element during iteration?
<p>Imagine you have a list of points in the 2D-space. I am trying to find symmetric points.</p>

<p>For doing that I iterate over my list of points and apply symmetry operations. So suppose I apply one of these operations to the first point and after this operation it is equal to other point in the list. These 2 points are symmetric.</p>

<p>So what I want is to erase this other point from the list that I am iterating so in this way my iterating variable say "i" won't take this value. Because I already know that it is symmetric with the first point.</p>

<p>I have seen similar Posts but they remove a value in the list that they have already taken. What I want is to remove subsequent values.</p>

<p>In general it is a bad idea to remove values from a list you are iterating over. There are, however, another ways to skip the symmetric points. For example, you can check for each point if you have seen a symmetric one before:</p>

<pre><code>for i, point in enumerate(points):
    if symmetric(point) not in points[:i]:
        # Do whatever you want to do
</code></pre>

<p>Here <code>symmetric</code> produces a point according to your symmetry operation. If your symmetry operation connects more that two points you can do </p>

<pre><code>for i, point in enumerate(points):
    for sympoint in symmetric(point):
        if sympoint in points[:i]:
            break
    else:
        # Do whatever you want to do
</code></pre>

python python-2.7 loops iterator