3967: Replace a few lines with iteritems, list comps, dict.get