def rApply(d, f):
 remainingDicts = [(d, ())]
 while (len(remainingDicts) > 0):
  (current, prevKeys) = remainingDicts.pop()
  for (k, v) in current.iteritems():
   keys = (prevKeys + (k,))
   if isinstance(v, dict):
    remainingDicts.insert(0, (v, keys))
   else:
    f(v, keys)

def rApply ( d , f ) : remainingDicts = [ ( d , ( ) ) ] while ( len ( remainingDicts ) > 0 ) : ( current , prevKeys ) = remainingDicts . pop ( ) for ( k , v ) in current . iteritems ( ) : keys = ( prevKeys + ( k , ) ) if isinstance ( v , dict ) : remainingDicts . insert ( 0 , ( v , keys ) ) else : f ( v , keys )
recursively applies f to the values in dict d .