Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.beige.octanews.com.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> <4dc6f077$0$41117$e4fe514c@news.xs4all.nl> Date: Sun, 08 May 2011 12:42:23 -0700 Message-ID: <7xhb952d40.fsf@ruckus.brouhaha.com> Organization: Nightsong/Fort GNOX User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:wJHOmhSoUpFM17EaSJ2UxvS2xTs= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 12 NNTP-Posting-Date: 08 May 2011 14:42:23 CDT X-Complaints-To: abuse@octanews.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4964 Hans Mulder 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.