Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: TheSaint Newsgroups: comp.lang.python Subject: How to iterate on a changing dictionary Followup-To: comp.lang.python Date: Sun, 19 Jun 2011 22:32:36 +0800 Organization: Aioe.org NNTP Server Lines: 19 Message-ID: NNTP-Posting-Host: gvW2HTYoHE7qSFheogmpJQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.4.11 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7963 Hello Trying to pop some key from a dict while is iterating over it will cause an exception. How I can remove items when the search result is true. Example: while len(dict): for key in dict.keys(): if dict[key] is not my_result: dict.pop(key) else: condition_to_break print('Dictionary is over') this is my mistake, but where to fix? -- goto /dev/null