dictionary size changed during iteration

Paul Rubin no.email at nospam.invalid
Sat May 7 17:07:38 EDT 2011


Roy Smith <roy at panix.com> writes:
> changes = [ ]
> for key in d.iterkeys():
>   if is_bad(key):
>     changes.append(key)

    changes = list(k for k in d if is_bad(k))

is a little bit more direct.



More information about the Python-list mailing list