can't delete from a dictionary in a loop
Scott David Daniels
Scott.Daniels at Acm.Org
Sun May 18 00:25:06 EDT 2008
Eduardo O. Padoan wrote:
> On Fri, May 16, 2008 at 6:40 PM, Gary Herron <gherron at islandtraining.com> wrote:
>> bruno.desthuilliers at gmail.com wrote:
>>> On 16 mai, 23:28, Hans Nowak <zephyrfalcon!NO_SP... at gmail.com> wrote:
>>>
>>>> Dan Upton wrote:
<<asking about iterating over a dictionary and deleting elements>>
>>>> ...to solve the immediate problem:
>>>> for pid in procs_dict.keys():
>> And then, in Python3, keys() produces something else altogether (call a view
>> of the dictionary) which would provoke the same problem, so yet another
>> solution would have to be found then.
> In Python 3.0, list(procs_dict.keys()) would have the same effect.
Or (simpler in either 3.0 or 2.X):
for pid in list(procs_dict):
...
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list