"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > for item in alist: > if isnasty(item): > alist.remove(item) > > changing the header to ``in alist[:]:'' or ``in list(alist):'' probably > makes this code work, but it still can't make it GOOD... good would be: > > alist[:] = [item for item in alist if not isnasty(item)]
Given that the OP has verified that replacing alist with list(alist) in the for statement solves his problems, I agree that the listcomp is even nicer in that it avoids the bug trap, the over-copying of the entire list, the alternative of iterating in reverse, and the n**2 behavior of multiple correct deletes from a long list. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list