Index: Include/listobject.h =================================================================== --- Include/listobject.h (revision 58651) +++ Include/listobject.h (working copy) @@ -36,6 +36,7 @@ * the list is not yet visible outside the function that builds it. */ Py_ssize_t allocated; + int val_removed_state; } PyListObject; PyAPI_DATA(PyTypeObject) PyList_Type; Index: Objects/listobject.c =================================================================== --- Objects/listobject.c (revision 58651) +++ Objects/listobject.c (working copy) @@ -628,7 +628,7 @@ if (d < 0) { /* Delete -d items */ memmove(&item[ihigh+d], &item[ihigh], (Py_Size(a) - ihigh)*sizeof(PyObject *)); - list_resize(a, Py_Size(a) + d); + list_resize(a, Py_Size(a) +d); item = a->ob_item; } else if (d > 0) { /* Insert d items */ @@ -2273,7 +2273,10 @@ if (cmp > 0) { if (list_ass_slice(self, i, i+1, (PyObject *)NULL) == 0) - Py_RETURN_NONE; + { + self->val_removed_state = 1; + Py_RETURN_NONE; + } return NULL; } else if (cmp < 0) @@ -2390,6 +2393,7 @@ return -1; Py_DECREF(rv); } + self->val_removed_state=0; return 0; } @@ -2823,7 +2827,13 @@ seq = it->it_seq; if (seq == NULL) return NULL; - assert(PyList_Check(seq)); + assert(PyList_Check(seq)); + if(it->it_seq->val_removed_state) + { + if(it->it_index>0) + --it->it_index; + it->it_seq->val_removed_state = 0; + } if (it->it_index < PyList_GET_SIZE(seq)) { item = PyList_GET_ITEM(seq, it->it_index);