What is the proper way to delete selected items during iteration of a map? What I want to do is:

for (k, v) in m.items():
   if f(k):
      #  do some processing of v and save result elsewhere
      del m[k]

But this gives (as should be expected):
        RuntimeError: dictionary changed size during iteration
In the past I've accumulated the keys to be deleted in a separate list, but this time there are likely to be a large number of them, so is there some better way?

--
Charles Hixson

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to