The following code shows that this is incorrectly defined:
def f(x): return x def g(x): return x+1 def h(x): return x+10 try: d = {1:"a", 2:"b", 3:"c"} for k, v in d.iteritems(): del d[f(k)] d[g(k)] = v+"x" print d except Exception as e: print "Exception:", e try: d = {1:"a", 2:"b", 3:"c"} for k, v in d.iteritems(): del d[f(k)] d[h(k)] = v+"x" print d except Exception as e: print "Exception:", e
The first example calls g (k) and throws an exception (resized dictionary during iteration).
The second example calls h (k) and does not throw an exception, but outputs:
{21: 'axx', 22: 'bxx', 23: 'cxx'}
Which, looking at the code, seems wrong - I would expect something like:
{11: 'ax', 12: 'bx', 13: 'cx'}
combatdave Jul 21 2018-11-21T00: 00Z
source share