dictionary size changed during iteration

Paul Rubin no.email at nospam.invalid
Sun May 8 15:42:23 EDT 2011


Hans Mulder <hansmu at xs4all.nl> writes:
> How about:
> 	changes = filter(is_bad, d)
> Or would that be too compact?

I thought of writing something like that but filter in python 3 creates
an iterator that would have the same issue of walking the dictionary
while the dictionary is mutating.

    changes = list(filter(is_bad, d))

should work.



More information about the Python-list mailing list