when is the filter test applied?

Chris Angelico rosuav at gmail.com
Tue Oct 3 16:57:45 EDT 2017


On Wed, Oct 4, 2017 at 7:31 AM, ROGER GRAYDON CHRISTMAN <dvl at psu.edu> wrote:
>>> > for rb in filter (lambda b : b in some_seq, seq):
>>> >   ... some code that might modify some_seq
> I think one must always be very careful about modifying anything
> that you are iterating across -- if not avoiding that sort of thing entirely.
> In particular, avoid anything that might add or remove elements
> in the middle of the sequence.

It isn't, though. That's iterating over seq, and possibly modifying
some_seq. So it's safe.

ChrisA



More information about the Python-list mailing list